From 99c99b9218dc4e2d9307ba36a785f791fa14c096 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 31 May 2020 14:10:58 +0200 Subject: [PATCH] Window decorations: support embedding menu bar into title pane (enabled by default) (issues #47 and #82) --- .../formdev/flatlaf/FlatClientProperties.java | 9 +++ .../formdev/flatlaf/ui/FlatRootPaneUI.java | 59 ++++++++++++---- .../com/formdev/flatlaf/ui/FlatTitlePane.java | 68 +++++++++++++++++-- .../formdev/flatlaf/FlatDarkLaf.properties | 1 + .../com/formdev/flatlaf/FlatLaf.properties | 2 + .../formdev/flatlaf/FlatLightLaf.properties | 1 + .../com/formdev/flatlaf/demo/DemoFrame.java | 14 ++++ .../com/formdev/flatlaf/demo/DemoFrame.jfd | 9 +++ .../testing/FlatWindowDecorationsTest.java | 28 ++++++-- .../testing/FlatWindowDecorationsTest.jfd | 25 +++++-- .../uidefaults/FlatDarkLaf_1.8.0_202.txt | 26 +++++++ .../uidefaults/FlatLightLaf_1.8.0_202.txt | 26 +++++++ 12 files changed, 235 insertions(+), 33 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index ae53d724..baf2625d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -175,6 +175,15 @@ public interface FlatClientProperties */ String PROGRESS_BAR_SQUARE = "JProgressBar.square"; + /** + * Specifies whether the menu bar is embedded into the title pane if custom + * window decorations are enabled. Default is {@code true}. + *

+ * Component {@link javax.swing.JRootPane}
+ * Value type {@link java.lang.Boolean} + */ + String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded"; + /** * Specifies whether the decrease/increase arrow buttons of a scrollbar are shown. *

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 a1952205..1d2b6ce7 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 @@ -30,6 +30,7 @@ import javax.swing.JMenuBar; import javax.swing.JRootPane; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRootPaneUI; +import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.util.SystemInfo; /** @@ -41,7 +42,7 @@ public class FlatRootPaneUI extends BasicRootPaneUI { private JRootPane rootPane; - private JComponent titlePane; + private FlatTitlePane titlePane; private LayoutManager oldLayout; public static ComponentUI createUI( JComponent c ) { @@ -92,14 +93,17 @@ public class FlatRootPaneUI } } - private void setTitlePane( JComponent newTitlePane ) { + // layer title pane under frame content layer to allow placing menu bar over title pane + private final static Integer TITLE_PANE_LAYER = JLayeredPane.FRAME_CONTENT_LAYER - 1; + + private void setTitlePane( FlatTitlePane newTitlePane ) { JLayeredPane layeredPane = rootPane.getLayeredPane(); if( titlePane != null ) layeredPane.remove( titlePane ); if( newTitlePane != null ) - layeredPane.add( newTitlePane, JLayeredPane.FRAME_CONTENT_LAYER ); + layeredPane.add( newTitlePane, TITLE_PANE_LAYER ); titlePane = newTitlePane; } @@ -114,6 +118,14 @@ public class FlatRootPaneUI if( rootPane.getWindowDecorationStyle() != JRootPane.NONE ) installClientDecorations(); break; + + case FlatClientProperties.MENU_BAR_EMBEDDED: + if( titlePane != null ) { + titlePane.menuBarChanged(); + rootPane.revalidate(); + rootPane.repaint(); + } + break; } } @@ -125,7 +137,6 @@ public class FlatRootPaneUI @Override public void addLayoutComponent( String name, Component comp ) {} @Override public void addLayoutComponent( Component comp, Object constraints ) {} @Override public void removeLayoutComponent( Component comp ) {} - @Override public void invalidateLayout( Container target ) {} @Override public Dimension preferredLayoutSize( Container parent ) { @@ -144,20 +155,26 @@ public class FlatRootPaneUI private Dimension computeLayoutSize( Container parent, Function getSizeFunc ) { JRootPane rootPane = (JRootPane) parent; - JComponent titlePane = getTitlePane( rootPane ); + FlatTitlePane titlePane = getTitlePane( rootPane ); Dimension titlePaneSize = (titlePane != null) ? getSizeFunc.apply( titlePane ) : new Dimension(); - Dimension menuBarSize = (rootPane.getJMenuBar() != null) - ? getSizeFunc.apply( rootPane.getJMenuBar() ) - : new Dimension(); Dimension contentSize = (rootPane.getContentPane() != null) ? getSizeFunc.apply( rootPane.getContentPane() ) : rootPane.getSize(); - int width = Math.max( titlePaneSize.width, Math.max( menuBarSize.width, contentSize.width ) ); - int height = titlePaneSize.height + menuBarSize.height + contentSize.height; + int width = Math.max( titlePaneSize.width, contentSize.width ); + int height = titlePaneSize.height + contentSize.height; + if( titlePane == null || !titlePane.isMenuBarEmbedded() ) { + Dimension menuBarSize = (rootPane.getJMenuBar() != null) + ? getSizeFunc.apply( rootPane.getJMenuBar() ) + : new Dimension(); + + width = Math.max( width, menuBarSize.width ); + height += menuBarSize.height; + } + Insets insets = rootPane.getInsets(); return new Dimension( @@ -165,7 +182,7 @@ public class FlatRootPaneUI height + insets.top + insets.bottom ); } - private JComponent getTitlePane( JRootPane rootPane ) { + private FlatTitlePane getTitlePane( JRootPane rootPane ) { return (rootPane.getWindowDecorationStyle() != JRootPane.NONE && rootPane.getUI() instanceof FlatRootPaneUI) ? ((FlatRootPaneUI)rootPane.getUI()).titlePane @@ -188,7 +205,7 @@ public class FlatRootPaneUI rootPane.getGlassPane().setBounds( x, y, width, height ); int nextY = 0; - JComponent titlePane = getTitlePane( rootPane ); + FlatTitlePane titlePane = getTitlePane( rootPane ); if( titlePane != null ) { Dimension prefSize = titlePane.getPreferredSize(); titlePane.setBounds( 0, 0, width, prefSize.height ); @@ -197,9 +214,14 @@ public class FlatRootPaneUI JMenuBar menuBar = rootPane.getJMenuBar(); if( menuBar != null ) { - Dimension prefSize = menuBar.getPreferredSize(); - menuBar.setBounds( 0, nextY, width, prefSize.height ); - nextY += prefSize.height; + if( titlePane != null && titlePane.isMenuBarEmbedded() ) { + titlePane.validate(); + menuBar.setBounds( titlePane.getMenuBarBounds() ); + } else { + Dimension prefSize = menuBar.getPreferredSize(); + menuBar.setBounds( 0, nextY, width, prefSize.height ); + nextY += prefSize.height; + } } Container contentPane = rootPane.getContentPane(); @@ -207,6 +229,13 @@ public class FlatRootPaneUI contentPane.setBounds( 0, nextY, width, Math.max( height - nextY, 0 ) ); } + @Override + public void invalidateLayout( Container parent ) { + FlatTitlePane titlePane = getTitlePane( (JRootPane) parent ); + if( titlePane != null && titlePane.isMenuBarEmbedded() ) + titlePane.menuBarChanged(); + } + @Override public float getLayoutAlignmentX( Container target ) { return 0; 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 7a67ad8e..a656cb3f 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 @@ -48,10 +48,12 @@ import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.util.UIScale; /** @@ -61,9 +63,12 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault TitlePane.inactiveBackground Color * @uiDefault TitlePane.foreground Color * @uiDefault TitlePane.inactiveForeground Color + * @uiDefault TitlePane.embeddedForeground Color * @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 * @uiDefault TitlePane.iconifyIcon Icon @@ -79,13 +84,18 @@ class FlatTitlePane private final Color inactiveBackground = UIManager.getColor( "TitlePane.inactiveBackground" ); private final Color activeForeground = UIManager.getColor( "TitlePane.foreground" ); private final Color inactiveForeground = UIManager.getColor( "TitlePane.inactiveForeground" ); + private final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" ); + private final boolean menuBarEmbedded = UIManager.getBoolean( "TitlePane.menuBarEmbedded" ); + private final Insets menuBarMargins = UIManager.getInsets( "TitlePane.menuBarMargins" ); private final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" ); private final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" ); private final JRootPane rootPane; + private JPanel leftPanel; private JLabel iconLabel; + private JComponent menuBarPlaceholder; private JLabel titleLabel; private JPanel buttonPanel; private JButton iconifyButton; @@ -107,15 +117,32 @@ class FlatTitlePane } private void addSubComponents() { + leftPanel = new JPanel(); iconLabel = new JLabel(); titleLabel = new JLabel(); iconLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.iconMargins" ) ) ); titleLabel.setBorder( new FlatEmptyBorder( UIManager.getInsets( "TitlePane.titleMargins" ) ) ); + leftPanel.setBorder( new LineBorder( Color.red ) ); + leftPanel.setLayout( new BoxLayout( leftPanel, BoxLayout.LINE_AXIS ) ); + leftPanel.setOpaque( false ); + leftPanel.add( iconLabel ); + + menuBarPlaceholder = new JComponent() { + @Override + public Dimension getPreferredSize() { + JMenuBar menuBar = rootPane.getJMenuBar(); + return (menuBar != null && isMenuBarEmbedded()) + ? FlatUIUtils.addInsets( menuBar.getPreferredSize(), UIScale.scale( menuBarMargins ) ) + : new Dimension(); + } + }; + leftPanel.add( menuBarPlaceholder ); + createButtons(); setLayout( new BorderLayout() ); - add( iconLabel, BorderLayout.LINE_START ); + add( leftPanel, BorderLayout.LINE_START ); add( titleLabel, BorderLayout.CENTER ); add( buttonPanel, BorderLayout.LINE_END ); } @@ -169,7 +196,9 @@ class FlatTitlePane private void activeChanged( boolean active ) { Color background = FlatUIUtils.nonUIResource( active ? activeBackground : inactiveBackground ); - Color foreground = FlatUIUtils.nonUIResource( active ? activeForeground : inactiveForeground ); + Color foreground = FlatUIUtils.nonUIResource( active + ? (rootPane.getJMenuBar() != null && isMenuBarEmbedded() ? embeddedForeground : activeForeground) + : inactiveForeground ); setBackground( background ); titleLabel.setForeground( foreground ); @@ -278,6 +307,32 @@ class FlatTitlePane window.removeComponentListener( handler ); } + boolean isMenuBarEmbedded() { + return menuBarEmbedded && FlatClientProperties.clientPropertyBoolean( + rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true ); + } + + Rectangle getMenuBarBounds() { + Rectangle bounds = menuBarPlaceholder.getBounds(); + bounds = SwingUtilities.convertRectangle( menuBarPlaceholder.getParent(), bounds, rootPane ); + return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) ); + } + + void menuBarChanged() { + menuBarPlaceholder.invalidate(); + + // update title foreground color + EventQueue.invokeLater( () -> { + activeChanged( window == null || window.isActive() ); + } ); + } + + private Insets getMenuBarMargins() { + return getComponentOrientation().isLeftToRight() + ? menuBarMargins + : new Insets( menuBarMargins.top, menuBarMargins.right, menuBarMargins.bottom, menuBarMargins.left ); + } + @Override protected void paintComponent( Graphics g ) { g.setColor( getBackground() ); @@ -373,7 +428,8 @@ class FlatTitlePane return; List hitTestSpots = new ArrayList<>(); - addJBRHitTestSpot( buttonPanel, hitTestSpots ); + addJBRHitTestSpot( buttonPanel, false, hitTestSpots ); + addJBRHitTestSpot( menuBarPlaceholder, true, hitTestSpots );//TOOD int titleBarHeight = getHeight(); // slightly reduce height so that component receives mouseExit events @@ -383,13 +439,15 @@ class FlatTitlePane JBRCustomDecorations.setHitTestSpotsAndTitleBarHeight( window, hitTestSpots, titleBarHeight ); } - private void addJBRHitTestSpot( JComponent c, List hitTestSpots ) { + private void addJBRHitTestSpot( JComponent c, boolean subtractMenuBarMargins, List hitTestSpots ) { Dimension size = c.getSize(); if( size.width <= 0 || size.height <= 0 ) return; 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 ); @@ -506,7 +564,7 @@ class FlatTitlePane int restoredWidth = window.getWidth(); int newX = maximizedX; - JComponent rightComp = getComponentOrientation().isLeftToRight() ? buttonPanel : iconLabel; + JComponent rightComp = getComponentOrientation().isLeftToRight() ? buttonPanel : leftPanel; if( xOnScreen >= maximizedX + restoredWidth - rightComp.getWidth() - 10 ) newX = xOnScreen + rightComp.getWidth() + 10 - restoredWidth; diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 4eeadea6..99d7e083 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -268,6 +268,7 @@ TableHeader.bottomSeparatorColor=$TableHeader.separatorColor #---- TitlePane ---- +TitlePane.embeddedForeground=darken($TitlePane.foreground,15%) TitlePane.buttonHoverBackground=lighten($TitlePane.background,10%,derived) TitlePane.buttonPressedBackground=lighten($TitlePane.background,20%,derived) 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 6624ee2d..0f9748ec 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -576,8 +576,10 @@ TitledBorder.border=1,1,1,1,$Separator.foreground #---- TitlePane ---- +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.buttonSize=44,30 TitlePane.buttonMaximizedHeight=22 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 8982df4d..7f759756 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -275,6 +275,7 @@ TableHeader.bottomSeparatorColor=$TableHeader.separatorColor #---- TitlePane ---- +TitlePane.embeddedForeground=lighten($TitlePane.foreground,35%) TitlePane.buttonHoverBackground=darken($TitlePane.background,10%,derived) TitlePane.buttonPressedBackground=darken($TitlePane.background,20%,derived) diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index bf02a76e..51aa1967 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -23,6 +23,7 @@ import java.util.Arrays; import javax.swing.*; import javax.swing.text.DefaultEditorKit; import javax.swing.text.StyleContext; +import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.demo.extras.*; import com.formdev.flatlaf.demo.intellijthemes.*; @@ -71,6 +72,11 @@ class DemoFrame } ); } + private void menuBarEmbeddedChanged() { + getRootPane().putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, + menuBarEmbeddedCheckBoxMenuItem.isSelected() ? null : false ); + } + private void underlineMenuSelection() { UIManager.put( "MenuItem.selectionType", underlineMenuSelectionMenuItem.isSelected() ? "underline" : null ); } @@ -219,6 +225,7 @@ class DemoFrame JMenuItem incrFontMenuItem = new JMenuItem(); JMenuItem decrFontMenuItem = new JMenuItem(); JMenu optionsMenu = new JMenu(); + menuBarEmbeddedCheckBoxMenuItem = new JCheckBoxMenuItem(); underlineMenuSelectionMenuItem = new JCheckBoxMenuItem(); alwaysShowMnemonicsMenuItem = new JCheckBoxMenuItem(); JMenu helpMenu = new JMenu(); @@ -453,6 +460,12 @@ class DemoFrame { optionsMenu.setText("Options"); + //---- menuBarEmbeddedCheckBoxMenuItem ---- + menuBarEmbeddedCheckBoxMenuItem.setText("Embedded menu bar"); + menuBarEmbeddedCheckBoxMenuItem.setSelected(true); + menuBarEmbeddedCheckBoxMenuItem.addActionListener(e -> menuBarEmbeddedChanged()); + optionsMenu.add(menuBarEmbeddedCheckBoxMenuItem); + //---- underlineMenuSelectionMenuItem ---- underlineMenuSelectionMenuItem.setText("Use underline menu selection"); underlineMenuSelectionMenuItem.addActionListener(e -> underlineMenuSelection()); @@ -572,6 +585,7 @@ class DemoFrame // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JMenu fontMenu; + private JCheckBoxMenuItem menuBarEmbeddedCheckBoxMenuItem; private JCheckBoxMenuItem underlineMenuSelectionMenuItem; private JCheckBoxMenuItem alwaysShowMnemonicsMenuItem; private JTabbedPane tabbedPane; diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd index c2aec3f5..7675da4c 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd @@ -322,6 +322,15 @@ new FormModel { add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "optionsMenu" "text": "Options" + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "menuBarEmbeddedCheckBoxMenuItem" + "text": "Embedded menu bar" + "selected": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuBarEmbeddedChanged", false ) ) + } ) add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { name: "underlineMenuSelectionMenuItem" "text": "Use underline menu selection" 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 58f35611..2816e732 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 @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import javax.swing.*; +import com.formdev.flatlaf.FlatClientProperties; import net.miginfocom.swing.*; /** @@ -103,6 +104,12 @@ public class FlatWindowDecorationsTest } } + private void menuBarEmbeddedChanged() { + JRootPane rootPane = getWindowRootPane(); + if( rootPane != null ) + rootPane.putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED, menuBarEmbeddedCheckBox.isSelected() ); + } + private void resizableChanged() { Window window = SwingUtilities.windowForComponent( this ); if( window instanceof Frame ) @@ -178,6 +185,7 @@ public class FlatWindowDecorationsTest private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents menuBarCheckBox = new JCheckBox(); + menuBarEmbeddedCheckBox = new JCheckBox(); resizableCheckBox = new JCheckBox(); JLabel label1 = new JLabel(); JLabel label2 = new JLabel(); @@ -231,6 +239,7 @@ public class FlatWindowDecorationsTest "[fill]", // rows "para[]0" + + "[]0" + "[]" + "[]" + "[top]" + @@ -242,19 +251,25 @@ public class FlatWindowDecorationsTest menuBarCheckBox.addActionListener(e -> menuBarChanged()); add(menuBarCheckBox, "cell 0 0"); + //---- menuBarEmbeddedCheckBox ---- + menuBarEmbeddedCheckBox.setText("embedded menu bar"); + menuBarEmbeddedCheckBox.setSelected(true); + menuBarEmbeddedCheckBox.addActionListener(e -> menuBarEmbeddedChanged()); + add(menuBarEmbeddedCheckBox, "cell 0 1"); + //---- resizableCheckBox ---- resizableCheckBox.setText("resizable"); resizableCheckBox.setSelected(true); resizableCheckBox.addActionListener(e -> resizableChanged()); - add(resizableCheckBox, "cell 0 1"); + add(resizableCheckBox, "cell 0 2"); //---- label1 ---- label1.setText("Style:"); - add(label1, "cell 0 2"); + add(label1, "cell 0 3"); //---- label2 ---- label2.setText("Icon:"); - add(label2, "cell 1 2"); + add(label2, "cell 1 3"); //======== panel1 ======== { @@ -319,7 +334,7 @@ public class FlatWindowDecorationsTest styleFileChooserRadioButton.addActionListener(e -> decorationStyleChanged()); panel1.add(styleFileChooserRadioButton, "cell 0 8"); } - add(panel1, "cell 0 3"); + add(panel1, "cell 0 4"); //======== panel2 ======== { @@ -348,12 +363,12 @@ public class FlatWindowDecorationsTest iconTestRandomRadioButton.addActionListener(e -> iconChanged()); panel2.add(iconTestRandomRadioButton, "cell 0 2"); } - add(panel2, "cell 1 3"); + add(panel2, "cell 1 4"); //---- openDialogButton ---- openDialogButton.setText("Open Dialog"); openDialogButton.addActionListener(e -> openDialog()); - add(openDialogButton, "cell 0 4"); + add(openDialogButton, "cell 0 5"); //======== menuBar ======== { @@ -545,6 +560,7 @@ public class FlatWindowDecorationsTest // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JCheckBox menuBarCheckBox; + private JCheckBox menuBarEmbeddedCheckBox; private JCheckBox resizableCheckBox; private JRadioButton styleNoneRadioButton; private JRadioButton styleFrameRadioButton; 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 a9824228..5675caf2 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 @@ -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[fill]" - "$rowConstraints": "para[]0[][][top][]" + "$rowConstraints": "para[]0[]0[][][top][]" } ) { name: "this" add( new FormComponent( "javax.swing.JCheckBox" ) { @@ -23,6 +23,17 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 0" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "menuBarEmbeddedCheckBox" + "text": "embedded menu bar" + "selected": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "menuBarEmbeddedChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) add( new FormComponent( "javax.swing.JCheckBox" ) { name: "resizableCheckBox" "text": "resizable" @@ -32,19 +43,19 @@ new FormModel { } addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "resizableChanged", false ) ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 1" + "value": "cell 0 2" } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label1" "text": "Style:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 2" + "value": "cell 0 3" } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label2" "text": "Icon:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 2" + "value": "cell 1 3" } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[fill]" @@ -153,7 +164,7 @@ new FormModel { "value": "cell 0 8" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 3" + "value": "cell 0 4" } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[fill]" @@ -196,14 +207,14 @@ new FormModel { "value": "cell 0 2" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 3" + "value": "cell 1 4" } ) add( new FormComponent( "javax.swing.JButton" ) { name: "openDialogButton" "text": "Open Dialog" addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "openDialog", false ) ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 4" + "value": "cell 0 5" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt index cb6711f4..3d818fb4 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -1038,6 +1038,32 @@ TextPane.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] TextPaneUI com.formdev.flatlaf.ui.FlatTextPaneUI +#---- TitlePane ---- + +TitlePane.background #303234 javax.swing.plaf.ColorUIResource [UI] +TitlePane.buttonHoverBackground #484c4f com.formdev.flatlaf.util.DerivedColor [UI] lighten(10% autoInverse) +TitlePane.buttonMaximizedHeight 22 +TitlePane.buttonPressedBackground #616569 com.formdev.flatlaf.util.DerivedColor [UI] lighten(20% autoInverse) +TitlePane.buttonSize 44,30 javax.swing.plaf.DimensionUIResource [UI] +TitlePane.closeHoverBackground #e81123 javax.swing.plaf.ColorUIResource [UI] +TitlePane.closeHoverForeground #ffffff javax.swing.plaf.ColorUIResource [UI] +TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowCloseIcon [UI] +TitlePane.closePressedBackground #99e81123 javax.swing.plaf.ColorUIResource [UI] +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.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 #777777 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] + + #---- TitledBorder ---- TitledBorder.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatLineBorder [UI] lineColor=#515151 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000 diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt index f113f6fb..f584833e 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -1040,6 +1040,32 @@ TextPane.selectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] TextPaneUI com.formdev.flatlaf.ui.FlatTextPaneUI +#---- TitlePane ---- + +TitlePane.background #ffffff javax.swing.plaf.ColorUIResource [UI] +TitlePane.buttonHoverBackground #e6e6e6 com.formdev.flatlaf.util.DerivedColor [UI] darken(10% autoInverse) +TitlePane.buttonMaximizedHeight 22 +TitlePane.buttonPressedBackground #cccccc com.formdev.flatlaf.util.DerivedColor [UI] darken(20% autoInverse) +TitlePane.buttonSize 44,30 javax.swing.plaf.DimensionUIResource [UI] +TitlePane.closeHoverBackground #e81123 javax.swing.plaf.ColorUIResource [UI] +TitlePane.closeHoverForeground #ffffff javax.swing.plaf.ColorUIResource [UI] +TitlePane.closeIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowCloseIcon [UI] +TitlePane.closePressedBackground #99e81123 javax.swing.plaf.ColorUIResource [UI] +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.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] + + #---- TitledBorder ---- TitledBorder.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatLineBorder [UI] lineColor=#d1d1d1 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000