mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
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:
@@ -16,6 +16,9 @@ FlatLaf Change Log
|
||||
Platform Module System (JPMS) for application. (issue #289)
|
||||
- Native window decorations: Removed superfluous pixel-line at top of screen
|
||||
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)
|
||||
toolBar buttons. (issue #292; regression since fixing #112)
|
||||
- TabbedPane: Fixed NPE when creating/modifying in another thread. (issue #299)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -84,36 +85,39 @@ public class FlatMenuBarUI
|
||||
@Override
|
||||
public void update( Graphics g, JComponent c ) {
|
||||
// paint background
|
||||
if( isFillBackground( c ) ) {
|
||||
g.setColor( c.getBackground() );
|
||||
Color background = getBackground( c );
|
||||
if( background != null ) {
|
||||
g.setColor( background );
|
||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
||||
}
|
||||
|
||||
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
|
||||
if( c.isOpaque() || !(c.getBackground() instanceof UIResource) )
|
||||
return true;
|
||||
if( c.isOpaque() || !(background instanceof UIResource) )
|
||||
return background;
|
||||
|
||||
// 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;
|
||||
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)
|
||||
if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) &&
|
||||
FlatNativeWindowBorder.hasCustomDecoration( (Window) rootPane.getParent() ) )
|
||||
return false;
|
||||
return FlatUIUtils.getParentBackground( c );
|
||||
|
||||
// paint background in full screen mode
|
||||
if( FlatUIUtils.isFullScreen( rootPane ) )
|
||||
return true;
|
||||
return background;
|
||||
|
||||
// do not paint background if menu bar is embedded into title pane
|
||||
return !FlatRootPaneUI.isMenuBarEmbedded( rootPane );
|
||||
return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null :background;
|
||||
}
|
||||
|
||||
//---- class TakeFocus ----------------------------------------------------
|
||||
|
||||
@@ -525,10 +525,10 @@ debug*/
|
||||
@Override
|
||||
protected void paintComponent( Graphics g ) {
|
||||
// not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime
|
||||
if( !UIManager.getBoolean( "TitlePane.unifiedBackground" ) ) {
|
||||
g.setColor( getBackground() );
|
||||
g.fillRect( 0, 0, getWidth(), getHeight() );
|
||||
}
|
||||
g.setColor( UIManager.getBoolean( "TitlePane.unifiedBackground" )
|
||||
? FlatUIUtils.getParentBackground( this )
|
||||
: getBackground() );
|
||||
g.fillRect( 0, 0, getWidth(), getHeight() );
|
||||
}
|
||||
|
||||
protected void repaintWindowBorder() {
|
||||
|
||||
Reference in New Issue
Block a user