From f8ee8b27fb1e09a5ee367865d66a4b26e6a15e20 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 23 Mar 2021 15:08:01 +0100 Subject: [PATCH] InternalFrame: fixed translucent internal frame menu bar background if `TitlePane.unifiedBackground` is `true` (issue #274) --- CHANGELOG.md | 2 ++ .../com/formdev/flatlaf/ui/FlatMenuBarUI.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01386b3d..c1998569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ FlatLaf Change Log `frame.setVisible(true)`. (issue #277) - Custom window decorations: Fixed NPE in `FlatTitlePane.findHorizontalGlue()`. (issue #275) +- InternalFrame: Fixed translucent internal frame menu bar background if + `TitlePane.unifiedBackground` is `true`. (issue #274) ## 1.1 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 d6aa88b1..f40020cc 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.Graphics; +import java.awt.Window; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.ActionMap; @@ -86,7 +87,7 @@ public class FlatMenuBarUI @Override public void update( Graphics g, JComponent c ) { - // do not fill background if menubar is embedded into title pane + // paint background if( isFillBackground( c ) ) { g.setColor( c.getBackground() ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); @@ -96,21 +97,25 @@ public class FlatMenuBarUI } protected boolean isFillBackground( JComponent c ) { - // paint background in opaque or having custom background color + // paint background if opaque or if having custom background color if( c.isOpaque() || !(c.getBackground() instanceof UIResource) ) return true; + // paint background if menu bar is not the "main" menu bar + JRootPane rootPane = SwingUtilities.getRootPane( c ); + if( rootPane == null || !(rootPane.getParent() instanceof Window) || rootPane.getJMenuBar() != c ) + return true; + // do not paint background for unified title pane if( unifiedBackground ) return false; // paint background in full screen mode - JRootPane rootPane = SwingUtilities.getRootPane( c ); - if( rootPane == null || FlatUIUtils.isFullScreen( rootPane ) ) + if( FlatUIUtils.isFullScreen( rootPane ) ) return true; // do not paint background if menu bar is embedded into title pane - return rootPane.getJMenuBar() != c || !FlatRootPaneUI.isMenuBarEmbedded( rootPane ); + return !FlatRootPaneUI.isMenuBarEmbedded( rootPane ); } //---- class TakeFocus ----------------------------------------------------