diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java index 2c361941..6ba8d159 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuBarBorder.java @@ -53,7 +53,7 @@ public class FlatMenuBarBorder @Override public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { - if( !showBottomSeparator() ) + if( !showBottomSeparator( c ) ) return; float lineHeight = scale( (float) 1 ); @@ -73,7 +73,7 @@ public class FlatMenuBarBorder } /** @since 2 */ - protected boolean showBottomSeparator() { - return !UIManager.getBoolean( "TitlePane.unifiedBackground" ); + protected boolean showBottomSeparator( Component c ) { + return !FlatMenuBarUI.useUnifiedBackground( c ); } } 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 b2ffd44f..f1d9e038 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 @@ -17,6 +17,7 @@ package com.formdev.flatlaf.ui; import java.awt.Color; +import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; import java.awt.Window; @@ -189,10 +190,8 @@ public class FlatMenuBarUI return background; // use parent background for unified title pane - // (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime) - if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) && - FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ) ) - background = FlatUIUtils.getParentBackground( c ); + if( useUnifiedBackground( c ) ) + background = FlatUIUtils.getParentBackground( c ); // paint background in full screen mode if( FlatUIUtils.isFullScreen( rootPane ) ) @@ -202,6 +201,22 @@ public class FlatMenuBarUI return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null : background; } + /**@since 2 */ + static boolean useUnifiedBackground( Component c ) { + // check whether: + // - TitlePane.unifiedBackground is true and + // - menu bar is the "main" menu bar and + // - window has custom decorations enabled + + JRootPane rootPane; + // (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime) + return UIManager.getBoolean( "TitlePane.unifiedBackground" ) && + (rootPane = SwingUtilities.getRootPane( c )) != null && + rootPane.getParent() instanceof Window && + rootPane.getJMenuBar() == c && + FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ); + } + //---- class TakeFocus ---------------------------------------------------- /** 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 7ff684e6..128af0b4 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 @@ -870,7 +870,7 @@ debug*/ Border menuBarBorder = getMenuBarBorder(); if( menuBarBorder != null ) { // if menu bar is embedded, paint menu bar border - menuBarBorder.paintBorder( c, g, x, y, width, height ); + menuBarBorder.paintBorder( rootPane.getJMenuBar(), g, x, y, width, height ); } else if( borderColor != null && (rootPane.getJMenuBar() == null || !rootPane.getJMenuBar().isVisible()) ) { // paint border between title pane and content if border color is specified float lineHeight = UIScale.scale( (float) 1 );