Window decorations: support right aligned extra components in JFrame title pane with embedded menu bar

This commit is contained in:
Karl Tauber
2021-03-13 00:35:04 +01:00
parent d2ccb97eba
commit b7bcbccd45
11 changed files with 210 additions and 39 deletions

View File

@@ -1133,16 +1133,15 @@ TitlePane.closePressedBackground #e8112399 60% javax.swing.plaf.ColorUIResou
TitlePane.closePressedForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
TitlePane.embeddedForeground #959595 javax.swing.plaf.ColorUIResource [UI]
TitlePane.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI]
TitlePane.iconMargins 3,8,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconSize 16,16 javax.swing.plaf.DimensionUIResource [UI]
TitlePane.iconifyIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowIconifyIcon [UI]
TitlePane.inactiveBackground #303234 javax.swing.plaf.ColorUIResource [UI]
TitlePane.inactiveForeground #888888 javax.swing.plaf.ColorUIResource [UI]
TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI]
TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true

View File

@@ -1138,16 +1138,15 @@ TitlePane.closePressedBackground #e8112399 60% javax.swing.plaf.ColorUIResou
TitlePane.closePressedForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
TitlePane.embeddedForeground #595959 javax.swing.plaf.ColorUIResource [UI]
TitlePane.foreground #000000 javax.swing.plaf.ColorUIResource [UI]
TitlePane.iconMargins 3,8,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconSize 16,16 javax.swing.plaf.DimensionUIResource [UI]
TitlePane.iconifyIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowIconifyIcon [UI]
TitlePane.inactiveBackground #ffffff javax.swing.plaf.ColorUIResource [UI]
TitlePane.inactiveForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI]
TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true

View File

@@ -1130,16 +1130,15 @@ TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWin
TitlePane.closePressedBackground #e8112399 60% javax.swing.plaf.ColorUIResource [UI]
TitlePane.closePressedForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
TitlePane.foreground #0000ff javax.swing.plaf.ColorUIResource [UI]
TitlePane.iconMargins 3,8,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.iconSize 16,16 javax.swing.plaf.DimensionUIResource [UI]
TitlePane.iconifyIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowIconifyIcon [UI]
TitlePane.inactiveBackground #008800 javax.swing.plaf.ColorUIResource [UI]
TitlePane.inactiveForeground #ffffff javax.swing.plaf.ColorUIResource [UI]
TitlePane.maximizeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowMaximizeIcon [UI]
TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.titleMargins 3,0,3,0 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true

View File

@@ -128,13 +128,48 @@ public class FlatWindowDecorationsTest
menuBar.setVisible( menuBarVisibleCheckBox.isSelected() );
}
private void colorizeMenuBar() {
boolean colorize = colorizeMenuBarCheckBox.isSelected();
Color menuBarBackground = colorize ? new Color( 0xffccff ) : UIManager.getColor( "MenuBar.background" );
menuBar.setOpaque( colorize );
menuBar.setBackground( menuBarBackground );
}
private void colorizeMenus() {
boolean colorize = colorizeMenusCheckBox.isSelected();
Color menuBackground = colorize ? new Color( 0xaaffff ) : UIManager.getColor( "Menu.background" );
for( Component c : menuBar.getComponents() ) {
if( c instanceof JMenu ) {
((JMenu)c).setOpaque( colorize );
c.setBackground( menuBackground );
}
}
}
private void addMenu() {
JMenu menu = new JMenu( "Hello" );
menu.add( new JMenuItem( "world" ) );
if( colorizeMenusCheckBox.isSelected() ) {
menu.setOpaque( true );
menu.setBackground( new Color( 0xaaffff ) );
}
menuBar.add( menu );
menuBar.revalidate();
}
private void addGlue() {
for( Component c : menuBar.getComponents() ) {
if( c instanceof Box.Filler )
return;
}
menuBar.add( Box.createGlue() );
menuBar.revalidate();
}
private void removeMenu() {
int menuCount = menuBar.getMenuCount();
if( menuCount <= 0 )
@@ -264,10 +299,13 @@ public class FlatWindowDecorationsTest
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
menuBarCheckBox = new JCheckBox();
addMenuButton = new JButton();
JButton addGlueButton = new JButton();
removeMenuButton = new JButton();
changeMenuButton = new JButton();
menuBarEmbeddedCheckBox = new JCheckBox();
menuBarVisibleCheckBox = new JCheckBox();
colorizeMenuBarCheckBox = new JCheckBox();
colorizeMenusCheckBox = new JCheckBox();
resizableCheckBox = new JCheckBox();
maximizedBoundsCheckBox = new JCheckBox();
undecoratedCheckBox = new JCheckBox();
@@ -325,9 +363,9 @@ public class FlatWindowDecorationsTest
// rows
"para[]0" +
"[]0" +
"[]unrel" +
"[]0" +
"[]0" +
"[]" +
"[]unrel" +
"[]" +
"[top]" +
"[]"));
@@ -343,6 +381,11 @@ public class FlatWindowDecorationsTest
addMenuButton.addActionListener(e -> addMenu());
add(addMenuButton, "cell 1 0 1 2,align left top,grow 0 0");
//---- addGlueButton ----
addGlueButton.setText("Add glue");
addGlueButton.addActionListener(e -> addGlue());
add(addGlueButton, "cell 1 0 1 2,align left top,grow 0 0");
//---- removeMenuButton ----
removeMenuButton.setText("Remove menu");
removeMenuButton.addActionListener(e -> removeMenu());
@@ -365,6 +408,16 @@ public class FlatWindowDecorationsTest
menuBarVisibleCheckBox.addActionListener(e -> menuBarVisibleChanged());
add(menuBarVisibleCheckBox, "cell 0 2");
//---- colorizeMenuBarCheckBox ----
colorizeMenuBarCheckBox.setText("colorize menu bar");
colorizeMenuBarCheckBox.addActionListener(e -> colorizeMenuBar());
add(colorizeMenuBarCheckBox, "cell 1 2");
//---- colorizeMenusCheckBox ----
colorizeMenusCheckBox.setText("colorize menus");
colorizeMenusCheckBox.addActionListener(e -> colorizeMenus());
add(colorizeMenusCheckBox, "cell 1 2");
//---- resizableCheckBox ----
resizableCheckBox.setText("resizable");
resizableCheckBox.setSelected(true);
@@ -688,6 +741,8 @@ public class FlatWindowDecorationsTest
private JButton changeMenuButton;
private JCheckBox menuBarEmbeddedCheckBox;
private JCheckBox menuBarVisibleCheckBox;
private JCheckBox colorizeMenuBarCheckBox;
private JCheckBox colorizeMenusCheckBox;
private JCheckBox resizableCheckBox;
private JCheckBox maximizedBoundsCheckBox;
private JCheckBox undecoratedCheckBox;

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.2.0.298" Java: "15" encoding: "UTF-8"
JFDML JFormDesigner: "7.0.3.1.342" Java: "15" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -9,7 +9,7 @@ new FormModel {
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
"$columnConstraints": "[left]para[left]"
"$rowConstraints": "para[]0[]0[]0[]0[][][top][]"
"$rowConstraints": "para[]0[]0[]unrel[]0[]unrel[][top][]"
} ) {
name: "this"
add( new FormComponent( "javax.swing.JCheckBox" ) {
@@ -33,6 +33,13 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 1 2,align left top,grow 0 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "addGlueButton"
"text": "Add glue"
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "addGlue", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 0 1 2,align left top,grow 0 0"
} )
add( new FormComponent( "javax.swing.JButton" ) {
name: "removeMenuButton"
"text": "Remove menu"
@@ -75,6 +82,26 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "colorizeMenuBarCheckBox"
"text": "colorize menu bar"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "colorizeMenuBar", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "colorizeMenusCheckBox"
"text": "colorize menus"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "colorizeMenus", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "resizableCheckBox"
"text": "resizable"