mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 23:07:15 -06:00
Window decorations: added client properties to hide title, iconify, maximize/restore and close buttons (issue #608)
This commit is contained in:
@@ -346,7 +346,7 @@ public interface FlatClientProperties
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether the window icon should be shown in the window title bar
|
* Specifies whether the window icon should be shown in the window title bar
|
||||||
* (requires enabled window decorations).
|
* (requires enabled window decorations). Default is UI property {@code TitlePane.showIcon}.
|
||||||
* <p>
|
* <p>
|
||||||
* Setting this shows/hides the windows icon
|
* Setting this shows/hides the windows icon
|
||||||
* for the {@code JFrame} or {@code JDialog} that contains the root pane.
|
* for the {@code JFrame} or {@code JDialog} that contains the root pane.
|
||||||
@@ -362,6 +362,62 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String TITLE_BAR_SHOW_ICON = "JRootPane.titleBarShowIcon";
|
String TITLE_BAR_SHOW_ICON = "JRootPane.titleBarShowIcon";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether the window title should be shown in the window title bar
|
||||||
|
* (requires enabled window decorations). Default is {@code true}.
|
||||||
|
* <p>
|
||||||
|
* Setting this shows/hides the windows title
|
||||||
|
* for the {@code JFrame} or {@code JDialog} that contains the root pane.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||||
|
*
|
||||||
|
* @since 3
|
||||||
|
*/
|
||||||
|
String TITLE_BAR_SHOW_TITLE = "JRootPane.titleBarShowTitle";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether the "iconfify" button should be shown in the window title bar
|
||||||
|
* (requires enabled window decorations). Default is {@code true}.
|
||||||
|
* <p>
|
||||||
|
* Setting this shows/hides the "iconfify" button
|
||||||
|
* for the {@code JFrame} that contains the root pane.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||||
|
*
|
||||||
|
* @since 3
|
||||||
|
*/
|
||||||
|
String TITLE_BAR_SHOW_ICONIFFY = "JRootPane.titleBarShowIconify";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether the "maximize/restore" button should be shown in the window title bar
|
||||||
|
* (requires enabled window decorations). Default is {@code true}.
|
||||||
|
* <p>
|
||||||
|
* Setting this shows/hides the "maximize/restore" button
|
||||||
|
* for the {@code JFrame} that contains the root pane.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||||
|
*
|
||||||
|
* @since 3
|
||||||
|
*/
|
||||||
|
String TITLE_BAR_SHOW_MAXIMIZE = "JRootPane.titleBarShowMaximize";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether the "close" button should be shown in the window title bar
|
||||||
|
* (requires enabled window decorations). Default is {@code true}.
|
||||||
|
* <p>
|
||||||
|
* Setting this shows/hides the "close" button
|
||||||
|
* for the {@code JFrame} or {@code JDialog} that contains the root pane.
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||||
|
*
|
||||||
|
* @since 3
|
||||||
|
*/
|
||||||
|
String TITLE_BAR_SHOW_CLOSE = "JRootPane.titleBarShowClose";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background color of window title bar (requires enabled window decorations).
|
* Background color of window title bar (requires enabled window decorations).
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -349,6 +349,14 @@ public class FlatRootPaneUI
|
|||||||
titlePane.updateIcon();
|
titlePane.updateIcon();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FlatClientProperties.TITLE_BAR_SHOW_TITLE:
|
||||||
|
case FlatClientProperties.TITLE_BAR_SHOW_ICONIFFY:
|
||||||
|
case FlatClientProperties.TITLE_BAR_SHOW_MAXIMIZE:
|
||||||
|
case FlatClientProperties.TITLE_BAR_SHOW_CLOSE:
|
||||||
|
if( titlePane != null )
|
||||||
|
titlePane.updateVisibility();
|
||||||
|
break;
|
||||||
|
|
||||||
case FlatClientProperties.TITLE_BAR_BACKGROUND:
|
case FlatClientProperties.TITLE_BAR_BACKGROUND:
|
||||||
case FlatClientProperties.TITLE_BAR_FOREGROUND:
|
case FlatClientProperties.TITLE_BAR_FOREGROUND:
|
||||||
if( titlePane != null )
|
if( titlePane != null )
|
||||||
|
|||||||
@@ -354,15 +354,12 @@ public class FlatTitlePane
|
|||||||
if( window == null || rootPane.getWindowDecorationStyle() != JRootPane.FRAME )
|
if( window == null || rootPane.getWindowDecorationStyle() != JRootPane.FRAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
updateVisibility();
|
||||||
|
|
||||||
if( window instanceof Frame ) {
|
if( window instanceof Frame ) {
|
||||||
Frame frame = (Frame) window;
|
Frame frame = (Frame) window;
|
||||||
boolean resizable = frame.isResizable();
|
|
||||||
boolean maximized = ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0);
|
boolean maximized = ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0);
|
||||||
|
|
||||||
iconifyButton.setVisible( true );
|
|
||||||
maximizeButton.setVisible( resizable && !maximized );
|
|
||||||
restoreButton.setVisible( resizable && maximized );
|
|
||||||
|
|
||||||
if( maximized &&
|
if( maximized &&
|
||||||
!(SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window )) &&
|
!(SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window )) &&
|
||||||
rootPane.getClientProperty( "_flatlaf.maximizedBoundsUpToDate" ) == null )
|
rootPane.getClientProperty( "_flatlaf.maximizedBoundsUpToDate" ) == null )
|
||||||
@@ -383,14 +380,27 @@ public class FlatTitlePane
|
|||||||
frame.setExtendedState( oldExtendedState );
|
frame.setExtendedState( oldExtendedState );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 3 */
|
||||||
|
protected void updateVisibility() {
|
||||||
|
titleLabel.setVisible( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_TITLE, true ) );
|
||||||
|
closeButton.setVisible( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_CLOSE, true ) );
|
||||||
|
|
||||||
|
if( window instanceof Frame ) {
|
||||||
|
Frame frame = (Frame) window;
|
||||||
|
boolean maximizable = frame.isResizable() && clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_MAXIMIZE, true );
|
||||||
|
boolean maximized = ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0);
|
||||||
|
|
||||||
|
iconifyButton.setVisible( clientPropertyBoolean( rootPane, TITLE_BAR_SHOW_ICONIFFY, true ) );
|
||||||
|
maximizeButton.setVisible( maximizable && !maximized );
|
||||||
|
restoreButton.setVisible( maximizable && maximized );
|
||||||
} else {
|
} else {
|
||||||
// hide buttons because they are only supported in frames
|
// hide buttons because they are only supported in frames
|
||||||
iconifyButton.setVisible( false );
|
iconifyButton.setVisible( false );
|
||||||
maximizeButton.setVisible( false );
|
maximizeButton.setVisible( false );
|
||||||
restoreButton.setVisible( false );
|
restoreButton.setVisible( false );
|
||||||
|
|
||||||
revalidate();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,6 +446,30 @@ debug*/
|
|||||||
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_ICON, showIconCheckBox.getChecked() );
|
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_ICON, showIconCheckBox.getChecked() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showTitleChanged() {
|
||||||
|
JRootPane rootPane = getWindowRootPane();
|
||||||
|
if( rootPane != null )
|
||||||
|
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_TITLE, showTitleCheckBox.isSelected() ? null : false );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showIconifyChanged() {
|
||||||
|
JRootPane rootPane = getWindowRootPane();
|
||||||
|
if( rootPane != null )
|
||||||
|
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_ICONIFFY, showIconifyCheckBox.isSelected() ? null : false );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showMaximizeChanged() {
|
||||||
|
JRootPane rootPane = getWindowRootPane();
|
||||||
|
if( rootPane != null )
|
||||||
|
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_MAXIMIZE, showMaximizeCheckBox.isSelected() ? null : false );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCloseChanged() {
|
||||||
|
JRootPane rootPane = getWindowRootPane();
|
||||||
|
if( rootPane != null )
|
||||||
|
rootPane.putClientProperty( FlatClientProperties.TITLE_BAR_SHOW_CLOSE, showCloseCheckBox.isSelected() ? null : false );
|
||||||
|
}
|
||||||
|
|
||||||
private JRootPane getWindowRootPane() {
|
private JRootPane getWindowRootPane() {
|
||||||
Window window = SwingUtilities.windowForComponent( this );
|
Window window = SwingUtilities.windowForComponent( this );
|
||||||
if( window instanceof JFrame )
|
if( window instanceof JFrame )
|
||||||
@@ -495,7 +519,12 @@ debug*/
|
|||||||
iconTestRandomRadioButton = new JRadioButton();
|
iconTestRandomRadioButton = new JRadioButton();
|
||||||
iconTestMRIRadioButton = new JRadioButton();
|
iconTestMRIRadioButton = new JRadioButton();
|
||||||
iconTestDynMRIRadioButton = new JRadioButton();
|
iconTestDynMRIRadioButton = new JRadioButton();
|
||||||
|
JPanel panel4 = new JPanel();
|
||||||
showIconCheckBox = new FlatTriStateCheckBox();
|
showIconCheckBox = new FlatTriStateCheckBox();
|
||||||
|
showTitleCheckBox = new JCheckBox();
|
||||||
|
showIconifyCheckBox = new JCheckBox();
|
||||||
|
showMaximizeCheckBox = new JCheckBox();
|
||||||
|
showCloseCheckBox = new JCheckBox();
|
||||||
JButton openDialogButton = new JButton();
|
JButton openDialogButton = new JButton();
|
||||||
JButton openFrameButton = new JButton();
|
JButton openFrameButton = new JButton();
|
||||||
menuBar = new JMenuBar();
|
menuBar = new JMenuBar();
|
||||||
@@ -771,13 +800,52 @@ debug*/
|
|||||||
iconTestDynMRIRadioButton.setText("test dynamic multi-resolution (Java 9+)");
|
iconTestDynMRIRadioButton.setText("test dynamic multi-resolution (Java 9+)");
|
||||||
iconTestDynMRIRadioButton.addActionListener(e -> iconChanged());
|
iconTestDynMRIRadioButton.addActionListener(e -> iconChanged());
|
||||||
panel2.add(iconTestDynMRIRadioButton, "cell 0 4");
|
panel2.add(iconTestDynMRIRadioButton, "cell 0 4");
|
||||||
|
}
|
||||||
|
add(panel2, "cell 1 8");
|
||||||
|
|
||||||
|
//======== panel4 ========
|
||||||
|
{
|
||||||
|
panel4.setLayout(new MigLayout(
|
||||||
|
"ltr,insets 0,hidemode 3,gap 0 0",
|
||||||
|
// columns
|
||||||
|
"[grow,left]",
|
||||||
|
// rows
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]" +
|
||||||
|
"[]"));
|
||||||
|
|
||||||
//---- showIconCheckBox ----
|
//---- showIconCheckBox ----
|
||||||
showIconCheckBox.setText("show icon");
|
showIconCheckBox.setText("show icon");
|
||||||
showIconCheckBox.addActionListener(e -> showIconChanged());
|
showIconCheckBox.addActionListener(e -> showIconChanged());
|
||||||
panel2.add(showIconCheckBox, "cell 0 5");
|
panel4.add(showIconCheckBox, "cell 0 0");
|
||||||
|
|
||||||
|
//---- showTitleCheckBox ----
|
||||||
|
showTitleCheckBox.setText("show title");
|
||||||
|
showTitleCheckBox.setSelected(true);
|
||||||
|
showTitleCheckBox.addActionListener(e -> showTitleChanged());
|
||||||
|
panel4.add(showTitleCheckBox, "cell 0 1");
|
||||||
|
|
||||||
|
//---- showIconifyCheckBox ----
|
||||||
|
showIconifyCheckBox.setText("show iconfiy");
|
||||||
|
showIconifyCheckBox.setSelected(true);
|
||||||
|
showIconifyCheckBox.addActionListener(e -> showIconifyChanged());
|
||||||
|
panel4.add(showIconifyCheckBox, "cell 0 2");
|
||||||
|
|
||||||
|
//---- showMaximizeCheckBox ----
|
||||||
|
showMaximizeCheckBox.setText("show maximize");
|
||||||
|
showMaximizeCheckBox.setSelected(true);
|
||||||
|
showMaximizeCheckBox.addActionListener(e -> showMaximizeChanged());
|
||||||
|
panel4.add(showMaximizeCheckBox, "cell 0 3");
|
||||||
|
|
||||||
|
//---- showCloseCheckBox ----
|
||||||
|
showCloseCheckBox.setText("show close");
|
||||||
|
showCloseCheckBox.setSelected(true);
|
||||||
|
showCloseCheckBox.addActionListener(e -> showCloseChanged());
|
||||||
|
panel4.add(showCloseCheckBox, "cell 0 4");
|
||||||
}
|
}
|
||||||
add(panel2, "cell 1 8");
|
add(panel4, "cell 2 8");
|
||||||
|
|
||||||
//---- openDialogButton ----
|
//---- openDialogButton ----
|
||||||
openDialogButton.setText("Open Dialog");
|
openDialogButton.setText("Open Dialog");
|
||||||
@@ -1015,6 +1083,10 @@ debug*/
|
|||||||
private JRadioButton iconTestMRIRadioButton;
|
private JRadioButton iconTestMRIRadioButton;
|
||||||
private JRadioButton iconTestDynMRIRadioButton;
|
private JRadioButton iconTestDynMRIRadioButton;
|
||||||
private FlatTriStateCheckBox showIconCheckBox;
|
private FlatTriStateCheckBox showIconCheckBox;
|
||||||
|
private JCheckBox showTitleCheckBox;
|
||||||
|
private JCheckBox showIconifyCheckBox;
|
||||||
|
private JCheckBox showMaximizeCheckBox;
|
||||||
|
private JCheckBox showCloseCheckBox;
|
||||||
private JMenuBar menuBar;
|
private JMenuBar menuBar;
|
||||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
JFDML JFormDesigner: "7.0.3.1.342" Java: "16" encoding: "UTF-8"
|
JFDML JFormDesigner: "8.0.0.0.194" Java: "17.0.2" encoding: "UTF-8"
|
||||||
|
|
||||||
new FormModel {
|
new FormModel {
|
||||||
contentType: "form/swing"
|
contentType: "form/swing"
|
||||||
@@ -398,6 +398,15 @@ new FormModel {
|
|||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 4"
|
"value": "cell 0 4"
|
||||||
} )
|
} )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 1 8"
|
||||||
|
} )
|
||||||
|
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||||
|
"$layoutConstraints": "ltr,insets 0,hidemode 3,gap 0 0"
|
||||||
|
"$columnConstraints": "[grow,left]"
|
||||||
|
"$rowConstraints": "[][][][][]"
|
||||||
|
} ) {
|
||||||
|
name: "panel4"
|
||||||
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatTriStateCheckBox" ) {
|
add( new FormComponent( "com.formdev.flatlaf.extras.components.FlatTriStateCheckBox" ) {
|
||||||
name: "showIconCheckBox"
|
name: "showIconCheckBox"
|
||||||
"text": "show icon"
|
"text": "show icon"
|
||||||
@@ -406,10 +415,54 @@ new FormModel {
|
|||||||
}
|
}
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showIconChanged", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showIconChanged", false ) )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 0 5"
|
"value": "cell 0 0"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "showTitleCheckBox"
|
||||||
|
"text": "show title"
|
||||||
|
"selected": true
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTitleChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 1"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "showIconifyCheckBox"
|
||||||
|
"text": "show iconfiy"
|
||||||
|
"selected": true
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showIconifyChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 2"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "showMaximizeCheckBox"
|
||||||
|
"text": "show maximize"
|
||||||
|
"selected": true
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showMaximizeChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 3"
|
||||||
|
} )
|
||||||
|
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||||
|
name: "showCloseCheckBox"
|
||||||
|
"text": "show close"
|
||||||
|
"selected": true
|
||||||
|
auxiliary() {
|
||||||
|
"JavaCodeGenerator.variableLocal": false
|
||||||
|
}
|
||||||
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showCloseChanged", false ) )
|
||||||
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
"value": "cell 0 4"
|
||||||
} )
|
} )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
"value": "cell 1 8"
|
"value": "cell 2 8"
|
||||||
} )
|
} )
|
||||||
add( new FormComponent( "javax.swing.JButton" ) {
|
add( new FormComponent( "javax.swing.JButton" ) {
|
||||||
name: "openDialogButton"
|
name: "openDialogButton"
|
||||||
|
|||||||
Reference in New Issue
Block a user