diff --git a/CHANGELOG.md b/CHANGELOG.md index 344f6716..7a0f54ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ FlatLaf Change Log and embedded menu bar with all JREs, while still having native Windows 10 border drop shadows, resize behavior, window snapping and system window menu. (PR #267) +- Support right aligned components in `JFrame` title bar with embedded menu bar + (using `Box.createHorizontalGlue()`). (PR #268) #### Fixed bugs diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java index 09af41dd..5c596185 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarUI.java @@ -16,18 +16,21 @@ package com.formdev.flatlaf.ui; +import java.awt.Graphics; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.LookAndFeel; import javax.swing.MenuElement; import javax.swing.MenuSelectionManager; import javax.swing.SwingUtilities; import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuBarUI; +import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.util.SystemInfo; @@ -55,6 +58,13 @@ public class FlatMenuBarUI * Do not add any functionality here. */ + @Override + protected void installDefaults() { + super.installDefaults(); + + LookAndFeel.installProperty( menuBar, "opaque", false ); + } + @Override protected void installKeyboardActions() { super.installKeyboardActions(); @@ -67,6 +77,19 @@ public class FlatMenuBarUI map.put( "takeFocus", new TakeFocus() ); } + @Override + public void update( Graphics g, JComponent c ) { + // do not fill background if menubar is embedded into title pane + if( c.isOpaque() || + !FlatClientProperties.clientPropertyBoolean( menuBar, "flatlaf.internal.menuBarEmbedded", false ) ) + { + g.setColor( c.getBackground() ); + g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); + } + + paint( g, c ); + } + //---- class TakeFocus ---------------------------------------------------- /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java index 40ca3e98..888fbe8e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java @@ -305,7 +305,8 @@ public class FlatRootPaneUI JMenuBar menuBar = rootPane.getJMenuBar(); if( menuBar != null && menuBar.isVisible() ) { - if( !isFullScreen && titlePane != null && titlePane.isMenuBarEmbedded() ) { + boolean embedded = !isFullScreen && titlePane != null && titlePane.isMenuBarEmbedded(); + if( embedded ) { titlePane.validate(); menuBar.setBounds( titlePane.getMenuBarBounds() ); } else { @@ -313,6 +314,9 @@ public class FlatRootPaneUI menuBar.setBounds( 0, nextY, width, prefSize.height ); nextY += prefSize.height; } + + // mark menubar as embedded, which is used when painting menubar background + menuBar.putClientProperty( "flatlaf.internal.menuBarEmbedded", embedded ? true : null ); } Container contentPane = rootPane.getContentPane(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 52d7a82f..ffe0df7f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -47,6 +47,7 @@ import java.util.List; import java.util.Objects; import javax.accessibility.AccessibleContext; import javax.swing.BorderFactory; +import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -80,7 +81,6 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault TitlePane.iconSize Dimension * @uiDefault TitlePane.iconMargins Insets * @uiDefault TitlePane.titleMargins Insets - * @uiDefault TitlePane.menuBarMargins Insets * @uiDefault TitlePane.menuBarEmbedded boolean * @uiDefault TitlePane.buttonMaximizedHeight int * @uiDefault TitlePane.closeIcon Icon @@ -100,7 +100,6 @@ public class FlatTitlePane protected final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" ); protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" ); - protected final Insets menuBarMargins = UIManager.getInsets( "TitlePane.menuBarMargins" ); protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" ); protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" ); @@ -159,9 +158,7 @@ public class FlatTitlePane @Override public Dimension getPreferredSize() { JMenuBar menuBar = rootPane.getJMenuBar(); - return (menuBar != null && menuBar.isVisible() && isMenuBarEmbedded()) - ? FlatUIUtils.addInsets( menuBar.getPreferredSize(), UIScale.scale( menuBarMargins ) ) - : new Dimension(); + return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getPreferredSize() : new Dimension(); } }; leftPanel.add( menuBarPlaceholder ); @@ -184,6 +181,18 @@ public class FlatTitlePane if( !getComponentOrientation().isLeftToRight() ) leftPanel.setLocation( leftPanel.getX() + (oldWidth - newWidth), leftPanel.getY() ); } + + // If menu bar is embedded and contains a horizontal glue component, + // then move the title label to the same location as the glue component. + // This allows placing any component on the trailing side of the title pane. + JMenuBar menuBar = rootPane.getJMenuBar(); + if( hasVisibleEmbeddedMenuBar( menuBar ) ) { + Component horizontalGlue = findHorizontalGlue( menuBar ); + if( horizontalGlue != null ) { + Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, titleLabel ); + titleLabel.setLocation( titleLabel.getX() + glueLocation.x, titleLabel.getY() ); + } + } } } ); @@ -240,7 +249,7 @@ public class FlatTitlePane } protected void activeChanged( boolean active ) { - boolean hasEmbeddedMenuBar = rootPane.getJMenuBar() != null && rootPane.getJMenuBar().isVisible() && isMenuBarEmbedded(); + boolean hasEmbeddedMenuBar = hasVisibleEmbeddedMenuBar( rootPane.getJMenuBar() ); Color background = FlatUIUtils.nonUIResource( active ? activeBackground : inactiveBackground ); Color foreground = FlatUIUtils.nonUIResource( active ? activeForeground : inactiveForeground ); Color titleForeground = (hasEmbeddedMenuBar && active) ? FlatUIUtils.nonUIResource( embeddedForeground ) : foreground; @@ -394,6 +403,16 @@ public class FlatTitlePane window.removeComponentListener( handler ); } + /** + * Returns whether this title pane currently has an visible and embedded menubar. + */ + protected boolean hasVisibleEmbeddedMenuBar( JMenuBar menuBar ) { + return menuBar != null && menuBar.isVisible() && isMenuBarEmbedded(); + } + + /** + * Returns whether the menubar should be embedded into the title pane. + */ protected boolean isMenuBarEmbedded() { // not storing value of "TitlePane.menuBarEmbedded" in class to allow changing at runtime return UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) && @@ -412,13 +431,30 @@ public class FlatTitlePane Insets borderInsets = getBorder().getBorderInsets( this ); bounds.height += borderInsets.bottom; - return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) ); + // If menu bar is embedded and contains a horizontal glue component, + // then make the menu bar wider so that it completely overlaps the title label. + // Since the menu bar is not opaque, the title label is still visible. + // The title label is moved to the location of the glue component by the layout manager. + // This allows placing any component on the trailing side of the title pane. + Component horizontalGlue = findHorizontalGlue( rootPane.getJMenuBar() ); + if( horizontalGlue != null ) { + int titleWidth = Math.max( titleLabel.getWidth(), 0 ); // title width may be negative + bounds.width += titleWidth; + if( !getComponentOrientation().isLeftToRight() ) + bounds.x -= titleWidth; + } + + return bounds; } - protected Insets getMenuBarMargins() { - return getComponentOrientation().isLeftToRight() - ? menuBarMargins - : new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left ); + protected Component findHorizontalGlue( JMenuBar menuBar ) { + int count = menuBar.getComponentCount(); + for( int i = count - 1; i >= 0; i-- ) { + Component c = menuBar.getComponent( i ); + if( c instanceof Box.Filler && c.getMaximumSize().width >= Short.MAX_VALUE ) + return c; + } + return null; } protected void menuBarChanged() { @@ -654,8 +690,37 @@ debug*/ else appIconBounds = iconBounds; } - addNativeHitTestSpot( buttonPanel, false, hitTestSpots ); - addNativeHitTestSpot( menuBarPlaceholder, true, hitTestSpots ); + + Rectangle r = getNativeHitTestSpot( buttonPanel ); + if( r != null ) + hitTestSpots.add( r ); + + r = getNativeHitTestSpot( menuBarPlaceholder ); + if( r != null ) { + Component horizontalGlue = findHorizontalGlue( rootPane.getJMenuBar() ); + if( horizontalGlue != null ) { + // If menu bar is embedded and contains a horizontal glue component, + // then split the hit test spot into two spots so that + // the glue component area can used to move the window. + + Point glueLocation = SwingUtilities.convertPoint( horizontalGlue, 0, 0, window ); + Rectangle r2; + if( getComponentOrientation().isLeftToRight() ) { + int trailingWidth = (r.x + r.width - HIT_TEST_SPOT_GROW) - glueLocation.x; + r.width -= trailingWidth; + r2 = new Rectangle( glueLocation.x + horizontalGlue.getWidth(), r.y, trailingWidth, r.height ); + } else { + int leadingWidth = (glueLocation.x + horizontalGlue.getWidth()) - (r.x + HIT_TEST_SPOT_GROW); + r.x += leadingWidth; + r.width -= leadingWidth; + r2 = new Rectangle( glueLocation.x -leadingWidth, r.y, leadingWidth, r.height ); + } + r2.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW ); + hitTestSpots.add( r2 ); + } + + hitTestSpots.add( r ); + } FlatNativeWindowBorder.setTitleBarHeightAndHitTestSpots( window, titleBarHeight, hitTestSpots, appIconBounds ); @@ -667,27 +732,27 @@ debug*/ debug*/ } - protected void addNativeHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List hitTestSpots ) { + protected Rectangle getNativeHitTestSpot( JComponent c ) { Dimension size = c.getSize(); if( size.width <= 0 || size.height <= 0 ) - return; + return null; Point location = SwingUtilities.convertPoint( c, 0, 0, window ); Rectangle r = new Rectangle( location, size ); - if( subtractMenuBarMargins ) - r = FlatUIUtils.subtractInsets( r, UIScale.scale( getMenuBarMargins() ) ); // slightly increase rectangle so that component receives mouseExit events - r.grow( 2, 2 ); - hitTestSpots.add( r ); + r.grow( HIT_TEST_SPOT_GROW, HIT_TEST_SPOT_GROW ); + return r; } + private static final int HIT_TEST_SPOT_GROW = 2; + /*debug private int debugTitleBarHeight; private List debugHitTestSpots; private Rectangle debugAppIconBounds; debug*/ - //---- class TitlePaneBorder ---------------------------------------------- + //---- class FlatTitlePaneBorder ------------------------------------------ protected class FlatTitlePaneBorder extends AbstractBorder @@ -729,7 +794,7 @@ debug*/ protected Border getMenuBarBorder() { JMenuBar menuBar = rootPane.getJMenuBar(); - return (menuBar != null && menuBar.isVisible() && isMenuBarEmbedded()) ? menuBar.getBorder() : null; + return hasVisibleEmbeddedMenuBar( menuBar ) ? menuBar.getBorder() : null; } } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 580ff417..45a66b3e 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -688,9 +688,8 @@ TitledBorder.border = 1,1,1,1,$Separator.foreground TitlePane.useWindowDecorations = true TitlePane.menuBarEmbedded = true TitlePane.iconSize = 16,16 -TitlePane.iconMargins = 3,8,3,0 -TitlePane.menuBarMargins = 0,8,0,22 -TitlePane.titleMargins = 3,8,3,8 +TitlePane.iconMargins = 3,8,3,8 +TitlePane.titleMargins = 3,0,3,0 TitlePane.buttonSize = 44,30 TitlePane.buttonMaximizedHeight = 22 TitlePane.closeIcon = com.formdev.flatlaf.icons.FlatWindowCloseIcon diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt index 787ed4df..a4c45c88 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -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 diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt index 578a317e..f8da0584 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -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 diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt index c89dd1a6..361f9b13 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt @@ -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 diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java index d3ed01a0..9a835539 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.java @@ -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; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd index d536cc39..f1b87adc 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatWindowDecorationsTest.jfd @@ -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" diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index dd90b82a..7a766b57 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -850,7 +850,6 @@ TitlePane.inactiveBackground TitlePane.inactiveForeground TitlePane.maximizeIcon TitlePane.menuBarEmbedded -TitlePane.menuBarMargins TitlePane.restoreIcon TitlePane.titleMargins TitlePane.useWindowDecorations