Window decorations: fixed random window title bar background for unified backgrounds in cases were background is not filled by custom window/rootpane components (issue #254)

This commit is contained in:
Karl Tauber
2021-04-04 11:47:15 +02:00
parent eee177e64b
commit 801b555835
3 changed files with 21 additions and 14 deletions

View File

@@ -16,6 +16,9 @@ FlatLaf Change Log
Platform Module System (JPMS) for application. (issue #289) Platform Module System (JPMS) for application. (issue #289)
- Native window decorations: Removed superfluous pixel-line at top of screen - Native window decorations: Removed superfluous pixel-line at top of screen
when window is maximized. (issue #296) when window is maximized. (issue #296)
- Window decorations: Fixed random window title bar background in cases were
background is not filled by custom window/rootpane components and
`TitlePane.unifiedBackground` is `true`.
- Button and ToggleButton: Do not paint background of disabled (and unselected) - Button and ToggleButton: Do not paint background of disabled (and unselected)
toolBar buttons. (issue #292; regression since fixing #112) toolBar buttons. (issue #292; regression since fixing #112)
- TabbedPane: Fixed NPE when creating/modifying in another thread. (issue #299) - TabbedPane: Fixed NPE when creating/modifying in another thread. (issue #299)

View File

@@ -16,6 +16,7 @@
package com.formdev.flatlaf.ui; package com.formdev.flatlaf.ui;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@@ -84,36 +85,39 @@ public class FlatMenuBarUI
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
// paint background // paint background
if( isFillBackground( c ) ) { Color background = getBackground( c );
g.setColor( c.getBackground() ); if( background != null ) {
g.setColor( background );
g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
} }
paint( g, c ); paint( g, c );
} }
protected boolean isFillBackground( JComponent c ) { protected Color getBackground( JComponent c ) {
Color background = c.getBackground();
// paint background if opaque or if having custom background color // paint background if opaque or if having custom background color
if( c.isOpaque() || !(c.getBackground() instanceof UIResource) ) if( c.isOpaque() || !(background instanceof UIResource) )
return true; return background;
// paint background if menu bar is not the "main" menu bar // paint background if menu bar is not the "main" menu bar
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 true; return background;
// do not paint background for unified title pane // paint background for unified title pane in color of parent
// (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime) // (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime)
if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) && if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) &&
FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ) ) FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ) )
return false; return FlatUIUtils.getParentBackground( c );
// paint background in full screen mode // paint background in full screen mode
if( FlatUIUtils.isFullScreen( rootPane ) ) if( FlatUIUtils.isFullScreen( rootPane ) )
return true; return background;
// do not paint background if menu bar is embedded into title pane // do not paint background if menu bar is embedded into title pane
return !FlatRootPaneUI.isMenuBarEmbedded( rootPane ); return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null :background;
} }
//---- class TakeFocus ---------------------------------------------------- //---- class TakeFocus ----------------------------------------------------

View File

@@ -525,11 +525,11 @@ debug*/
@Override @Override
protected void paintComponent( Graphics g ) { protected void paintComponent( Graphics g ) {
// not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime // not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime
if( !UIManager.getBoolean( "TitlePane.unifiedBackground" ) ) { g.setColor( UIManager.getBoolean( "TitlePane.unifiedBackground" )
g.setColor( getBackground() ); ? FlatUIUtils.getParentBackground( this )
: getBackground() );
g.fillRect( 0, 0, getWidth(), getHeight() ); g.fillRect( 0, 0, getWidth(), getHeight() );
} }
}
protected void repaintWindowBorder() { protected void repaintWindowBorder() {
int width = rootPane.getWidth(); int width = rootPane.getWidth();