MenuBar: do not fill background if non-opaque and having custom background color (issue #409)

This commit is contained in:
Karl Tauber
2021-12-15 00:29:37 +01:00
parent 5fd5b1206e
commit 07c9ad484a
2 changed files with 9 additions and 3 deletions

View File

@@ -92,6 +92,8 @@ FlatLaf Change Log
#### Fixed bugs #### Fixed bugs
- MenuBar: Do not fill background if non-opaque and having custom background
color. (issue #409)
- InternalFrame: Fill background to avoid that parent may shine through internal - InternalFrame: Fill background to avoid that parent may shine through internal
frame if it contains non-opaque components. (better fix for issue #274) frame if it contains non-opaque components. (better fix for issue #274)

View File

@@ -180,11 +180,15 @@ public class FlatMenuBarUI
protected Color getBackground( JComponent c ) { protected Color getBackground( JComponent c ) {
Color background = c.getBackground(); Color background = c.getBackground();
// paint background if opaque or if having custom background color // paint background if opaque
if( c.isOpaque() || !(background instanceof UIResource) ) if( c.isOpaque() )
return background; return background;
// paint background if menu bar is not the "main" menu bar // do not paint background if non-opaque and having custom background color
if( !(background instanceof UIResource) )
return null;
// paint background if menu bar is not the "main" menu bar (e.g. in internal frame)
JRootPane rootPane = SwingUtilities.getRootPane( c ); JRootPane rootPane = SwingUtilities.getRootPane( c );
if( rootPane == null || !(rootPane.getParent() instanceof Window) || rootPane.getJMenuBar() != c ) if( rootPane == null || !(rootPane.getParent() instanceof Window) || rootPane.getJMenuBar() != c )
return background; return background;