mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
FlatTestFrame: fixed restore of default colors
This commit is contained in:
@@ -20,6 +20,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.plaf.ColorUIResource;
|
||||||
import net.miginfocom.swing.*;
|
import net.miginfocom.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,30 +166,28 @@ public class FlatTestFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void explicitColorsChanged() {
|
private void explicitColorsChanged() {
|
||||||
boolean explicit = explicitColorsCheckBox.isSelected();
|
EventQueue.invokeLater( () -> {
|
||||||
|
boolean explicit = explicitColorsCheckBox.isSelected();
|
||||||
|
ColorUIResource restoreColor = new ColorUIResource( Color.white );
|
||||||
|
|
||||||
for( Component c : content.getComponents() ) {
|
for( Component c : content.getComponents() ) {
|
||||||
c.setForeground( explicitColor( explicit, c, "foreground", Color.blue ) );
|
c.setForeground( explicit ? Color.blue : restoreColor );
|
||||||
c.setBackground( explicitColor( explicit, c, "background", Color.red ) );
|
c.setBackground( explicit ? Color.red : restoreColor );
|
||||||
|
|
||||||
if( c instanceof JScrollPane ) {
|
if( c instanceof JScrollPane ) {
|
||||||
Component view = ((JScrollPane)c).getViewport().getView();
|
Component view = ((JScrollPane)c).getViewport().getView();
|
||||||
if( view != null ) {
|
if( view != null ) {
|
||||||
view.setForeground( explicitColor( explicit, view, "foreground", Color.magenta ) );
|
view.setForeground( explicit ? Color.magenta : restoreColor );
|
||||||
view.setBackground( explicitColor( explicit, view, "background", Color.orange ) );
|
view.setBackground( explicit ? Color.orange : restoreColor );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color explicitColor( boolean explicit, Component c, String propertyName, Color explicitColor ) {
|
// because colors may depend on state (e.g. disabled JTextField)
|
||||||
if( explicit )
|
// it is best to update all UI delegates to get correct result
|
||||||
return explicitColor;
|
if( !explicit )
|
||||||
else {
|
SwingUtilities.updateComponentTreeUI( content );
|
||||||
String uiClassID = ((JComponent)c).getUIClassID();
|
} );
|
||||||
String key = uiClassID.substring( 0, uiClassID.length() - 2 ) + "." + propertyName;
|
|
||||||
return UIManager.getColor( key );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rightToLeftChanged() {
|
private void rightToLeftChanged() {
|
||||||
|
|||||||
Reference in New Issue
Block a user