Window decorations: support enabling/disabling unified title bar backgrounds at runtime without FlatLaf.updateUI()

This commit is contained in:
Karl Tauber
2021-03-30 01:34:34 +02:00
parent 7a2d0e7fcb
commit 1b5da0e1d1
4 changed files with 8 additions and 10 deletions

View File

@@ -53,8 +53,6 @@ import com.formdev.flatlaf.util.SystemInfo;
public class FlatMenuBarUI public class FlatMenuBarUI
extends BasicMenuBarUI extends BasicMenuBarUI
{ {
protected boolean unifiedBackground;
public static ComponentUI createUI( JComponent c ) { public static ComponentUI createUI( JComponent c ) {
return new FlatMenuBarUI(); return new FlatMenuBarUI();
} }
@@ -69,8 +67,6 @@ public class FlatMenuBarUI
super.installDefaults(); super.installDefaults();
LookAndFeel.installProperty( menuBar, "opaque", false ); LookAndFeel.installProperty( menuBar, "opaque", false );
unifiedBackground = UIManager.getBoolean( "TitlePane.unifiedBackground" );
} }
@Override @Override
@@ -107,7 +103,8 @@ public class FlatMenuBarUI
return true; return true;
// do not paint background for unified title pane // do not paint background for unified title pane
if( unifiedBackground ) // (not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime)
if( UIManager.getBoolean( "TitlePane.unifiedBackground" ) )
return false; return false;
// paint background in full screen mode // paint background in full screen mode

View File

@@ -105,7 +105,6 @@ public class FlatTitlePane
protected final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" ); protected final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" );
protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" ); protected final Color borderColor = UIManager.getColor( "TitlePane.borderColor" );
protected final boolean unifiedBackground = UIManager.getBoolean( "TitlePane.unifiedBackground" );
protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" ); protected final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" );
protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" ); protected final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" );
protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" ); protected final boolean centerTitle = UIManager.getBoolean( "TitlePane.centerTitle" );
@@ -523,7 +522,8 @@ debug*/
@Override @Override
protected void paintComponent( Graphics g ) { protected void paintComponent( Graphics g ) {
if( !unifiedBackground ) { // not storing value of "TitlePane.unifiedBackground" in class to allow changing at runtime
if( !UIManager.getBoolean( "TitlePane.unifiedBackground" ) ) {
g.setColor( getBackground() ); g.setColor( getBackground() );
g.fillRect( 0, 0, getWidth(), getHeight() ); g.fillRect( 0, 0, getWidth(), getHeight() );
} }

View File

@@ -172,7 +172,7 @@ class DemoFrame
private void unifiedTitleBar() { private void unifiedTitleBar() {
UIManager.put( "TitlePane.unifiedBackground", unifiedTitleBarMenuItem.isSelected() ); UIManager.put( "TitlePane.unifiedBackground", unifiedTitleBarMenuItem.isSelected() );
FlatLaf.updateUI(); repaint();
} }
private void underlineMenuSelection() { private void underlineMenuSelection() {

View File

@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import javax.swing.*; import javax.swing.*;
import com.formdev.flatlaf.FlatClientProperties; import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import net.miginfocom.swing.*; import net.miginfocom.swing.*;
/** /**
@@ -112,7 +111,9 @@ public class FlatWindowDecorationsTest
private void unifiedBackgroundChanged() { private void unifiedBackgroundChanged() {
UIManager.put( "TitlePane.unifiedBackground", unifiedBackgroundCheckBox.isSelected() ); UIManager.put( "TitlePane.unifiedBackground", unifiedBackgroundCheckBox.isSelected() );
FlatLaf.updateUI(); Window window = SwingUtilities.windowForComponent( this );
if( window != null )
window.repaint();
} }
private void menuBarChanged() { private void menuBarChanged() {