Native window decorations: support changing title bar background and foreground colors per window (via client property) also if unified window title bar is enabled

This commit is contained in:
Karl Tauber
2021-04-06 10:46:28 +02:00
parent c8db01c958
commit fe7f345661
2 changed files with 8 additions and 6 deletions

View File

@@ -106,18 +106,18 @@ public class FlatMenuBarUI
if( rootPane == null || !(rootPane.getParent() instanceof Window) || rootPane.getJMenuBar() != c )
return background;
// paint background for unified title pane in color of parent
// 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() ) )
return FlatUIUtils.getParentBackground( c );
background = FlatUIUtils.getParentBackground( c );
// paint background in full screen mode
if( FlatUIUtils.isFullScreen( rootPane ) )
return background;
// do not paint background if menu bar is embedded into title pane
return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null :background;
return FlatRootPaneUI.isMenuBarEmbedded( rootPane ) ? null : background;
}
//---- class TakeFocus ----------------------------------------------------

View File

@@ -16,6 +16,7 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.FlatClientProperties.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
@@ -265,8 +266,8 @@ public class FlatTitlePane
}
protected void activeChanged( boolean active ) {
Color background = FlatClientProperties.clientPropertyColor( rootPane, FlatClientProperties.TITLE_BAR_BACKGROUND, null );
Color foreground = FlatClientProperties.clientPropertyColor( rootPane, FlatClientProperties.TITLE_BAR_FOREGROUND, null );
Color background = clientPropertyColor( rootPane, TITLE_BAR_BACKGROUND, null );
Color foreground = clientPropertyColor( rootPane, TITLE_BAR_FOREGROUND, null );
Color titleForeground = foreground;
if( background == null )
background = FlatUIUtils.nonUIResource( active ? activeBackground : inactiveBackground );
@@ -537,7 +538,8 @@ debug*/
@Override
protected void paintComponent( Graphics g ) {
// not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime
g.setColor( UIManager.getBoolean( "TitlePane.unifiedBackground" )
g.setColor( (UIManager.getBoolean( "TitlePane.unifiedBackground" ) &&
clientPropertyColor( rootPane, TITLE_BAR_BACKGROUND, null ) == null)
? FlatUIUtils.getParentBackground( this )
: getBackground() );
g.fillRect( 0, 0, getWidth(), getHeight() );