diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index bc94627e..4acc3b3d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -393,6 +393,7 @@ public abstract class FlatLaf "EditorPane.inactiveBackground", "FormattedTextField.disabledBackground", "PasswordField.disabledBackground", + "RootPane.background", "Spinner.disabledBackground", "TextArea.disabledBackground", "TextArea.inactiveBackground", @@ -411,7 +412,8 @@ public abstract class FlatLaf "Spinner.disabledForeground", "ToggleButton.disabledText" ); putDefaults( defaults, defaults.getColor( "textText" ), - "DesktopIcon.foreground" ); + "DesktopIcon.foreground", + "RootPane.foreground" ); initFonts( defaults ); initIconColors( defaults, isDark() ); @@ -541,6 +543,9 @@ public abstract class FlatLaf if( key instanceof String && (((String)key).endsWith( ".font" ) || ((String)key).endsWith( "Font" )) ) defaults.put( key, activeFont ); } + + // add fonts that are not set in BasicLookAndFeel + defaults.put( "RootPane.font", activeFont ); } private void initDefaultFont( UIDefaults defaults ) { 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 3441c83f..61569936 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 @@ -66,6 +66,9 @@ import com.formdev.flatlaf.util.UIScale; * * * + * @uiDefault RootPane.font Font unused + * @uiDefault RootPane.background Color + * @uiDefault RootPane.foreground Color unused * @uiDefault RootPane.borderDragThickness int * @uiDefault RootPane.cornerDragWidth int * @uiDefault RootPane.honorFrameMinimumSizeOnResize boolean @@ -126,8 +129,23 @@ public class FlatRootPaneUI protected void installDefaults( JRootPane c ) { super.installDefaults( c ); + // Give the root pane useful background, foreground and font. + // Background is used for title bar and menu bar if native window decorations + // and unified background are enabled. + // Foreground and font are usually not used, but set for completeness. + // Not using LookAndFeel.installColorsAndFont() here because it will not work + // because the properties are null by default but inherit non-null values from parent. + if( !c.isBackgroundSet() || c.getBackground() instanceof UIResource ) + c.setBackground( UIManager.getColor( "RootPane.background" ) ); + if( !c.isForegroundSet() || c.getForeground() instanceof UIResource ) + c.setForeground( UIManager.getColor( "RootPane.foreground" ) ); + if( !c.isFontSet() || c.getFont() instanceof UIResource ) + c.setFont( UIManager.getFont( "RootPane.font" ) ); + // Update background color of JFrame or JDialog parent to avoid bad border // on HiDPI screens when switching from light to dark Laf. + // Window background color is also used in native window decorations + // to fill background when window is initially shown or when resizing window. // The background of JFrame is initialized in JFrame.frameInit() and // the background of JDialog in JDialog.dialogInit(), // but it was not updated when switching Laf. diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java index 48b3f3ef..da5efbad 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatInspector.java @@ -474,9 +474,9 @@ public class FlatInspector if( c instanceof JComponent ) appendRow( buf, "Border", toString( ((JComponent)c).getBorder(), classHierarchy ) ); - appendRow( buf, "Background", toString( c.getBackground() ) ); - appendRow( buf, "Foreground", toString( c.getForeground() ) ); - appendRow( buf, "Font", toString( c.getFont() ) ); + appendRow( buf, "Background", toString( c.getBackground() ) + (c.isBackgroundSet() ? "" : " NOT SET") ); + appendRow( buf, "Foreground", toString( c.getForeground() ) + (c.isBackgroundSet() ? "" : " NOT SET") ); + appendRow( buf, "Font", toString( c.getFont() ) + (c.isFontSet() ? "" : " NOT SET") ); if( c instanceof JComponent ) { try { diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt index bbb09e93..17e9a34d 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt @@ -818,6 +818,7 @@ Resizable.resizeBorder [lazy] 4,4,4,4 false com.formdev.flatlaf.ui.F #---- RootPane ---- RootPane.activeBorderColor #4d5154 HSL 206 4 32 com.formdev.flatlaf.util.DerivedColor [UI] lighten(7% autoInverse) +RootPane.background #3c3f41 HSL 204 4 25 javax.swing.plaf.ColorUIResource [UI] RootPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatRootPaneUI$FlatWindowBorder [UI] RootPane.borderDragThickness 5 RootPane.cornerDragWidth 16 @@ -830,6 +831,8 @@ RootPane.defaultButtonWindowKeyBindings length=8 [Ljava.lang.Object; [5] press [6] ctrl released ENTER [7] release +RootPane.font [active] $defaultFont [UI] +RootPane.foreground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI] RootPane.honorDialogMinimumSizeOnResize true RootPane.honorFrameMinimumSizeOnResize false RootPane.inactiveBorderColor #484c4e HSL 200 4 29 com.formdev.flatlaf.util.DerivedColor [UI] lighten(5% autoInverse) diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt index 36956763..9a5d461b 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt @@ -823,6 +823,7 @@ Resizable.resizeBorder [lazy] 4,4,4,4 false com.formdev.flatlaf.ui.F #---- RootPane ---- RootPane.activeBorderColor #737373 HSL 0 0 45 com.formdev.flatlaf.util.DerivedColor [UI] darken(50% autoInverse) +RootPane.background #f2f2f2 HSL 0 0 95 javax.swing.plaf.ColorUIResource [UI] RootPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatRootPaneUI$FlatWindowBorder [UI] RootPane.borderDragThickness 5 RootPane.cornerDragWidth 16 @@ -835,6 +836,8 @@ RootPane.defaultButtonWindowKeyBindings length=8 [Ljava.lang.Object; [5] press [6] ctrl released ENTER [7] release +RootPane.font [active] $defaultFont [UI] +RootPane.foreground #000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI] RootPane.honorDialogMinimumSizeOnResize true RootPane.honorFrameMinimumSizeOnResize false RootPane.inactiveBorderColor #a6a6a6 HSL 0 0 65 com.formdev.flatlaf.util.DerivedColor [UI] darken(30% autoInverse) diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt index f40c58d4..3e8490fd 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt @@ -833,6 +833,7 @@ Resizable.resizeBorder [lazy] 4,4,4,4 false com.formdev.flatlaf.ui.F #---- RootPane ---- +RootPane.background #ccffcc HSL 120 100 90 javax.swing.plaf.ColorUIResource [UI] RootPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatRootPaneUI$FlatWindowBorder [UI] RootPane.borderDragThickness 5 RootPane.cornerDragWidth 16 @@ -845,6 +846,8 @@ RootPane.defaultButtonWindowKeyBindings length=8 [Ljava.lang.Object; [5] press [6] ctrl released ENTER [7] release +RootPane.font [active] $defaultFont [UI] +RootPane.foreground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI] RootPane.honorDialogMinimumSizeOnResize true RootPane.honorFrameMinimumSizeOnResize false RootPaneUI com.formdev.flatlaf.ui.FlatRootPaneUI 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 3137b926..c2b5297f 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 @@ -631,10 +631,13 @@ RangeSliderUI Resizable.resizeBorder RootPane.activeBorderColor RootPane.ancestorInputMap +RootPane.background RootPane.border RootPane.borderDragThickness RootPane.cornerDragWidth RootPane.defaultButtonWindowKeyBindings +RootPane.font +RootPane.foreground RootPane.honorDialogMinimumSizeOnResize RootPane.honorFrameMinimumSizeOnResize RootPane.inactiveBorderColor