mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
ComboBox: fixed foreground colors and focused-not-editable background
This commit is contained in:
@@ -22,6 +22,7 @@ import java.awt.Container;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.LayoutManager;
|
import java.awt.LayoutManager;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
@@ -33,6 +34,7 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicArrowButton;
|
import javax.swing.plaf.basic.BasicArrowButton;
|
||||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||||
|
import javax.swing.text.JTextComponent;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,11 +82,11 @@ public class FlatComboBoxUI
|
|||||||
String propertyName = e.getPropertyName();
|
String propertyName = e.getPropertyName();
|
||||||
|
|
||||||
if( editor != null &&
|
if( editor != null &&
|
||||||
((source == comboBox && propertyName == "background") ||
|
((source == comboBox && (propertyName == "background" || propertyName == "foreground")) ||
|
||||||
(source == editor && propertyName == "enabled")) )
|
(source == editor && propertyName == "enabled")) )
|
||||||
{
|
{
|
||||||
// fix editor component background color
|
// fix editor component colors
|
||||||
updateEditorBackground();
|
updateEditorColors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -94,13 +96,19 @@ public class FlatComboBoxUI
|
|||||||
protected void configureEditor() {
|
protected void configureEditor() {
|
||||||
super.configureEditor();
|
super.configureEditor();
|
||||||
|
|
||||||
updateEditorBackground();
|
updateEditorColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEditorBackground() {
|
private void updateEditorColors() {
|
||||||
editor.setBackground( editor.isEnabled()
|
boolean enabled = editor.isEnabled();
|
||||||
|
editor.setBackground( enabled
|
||||||
? comboBox.getBackground()
|
? comboBox.getBackground()
|
||||||
: UIManager.getColor( "ComboBox.disabledBackground" ) );
|
: UIManager.getColor( "ComboBox.disabledBackground" ) );
|
||||||
|
editor.setForeground( (enabled || editor instanceof JTextComponent)
|
||||||
|
? comboBox.getForeground()
|
||||||
|
: UIManager.getColor( "ComboBox.disabledForeground" ) );
|
||||||
|
if( editor instanceof JTextComponent )
|
||||||
|
((JTextComponent)editor).setDisabledTextColor( UIManager.getColor( "ComboBox.disabledForeground" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,6 +157,12 @@ public class FlatComboBoxUI
|
|||||||
paint( g, c );
|
paint( g, c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
|
||||||
|
// always pass "hasFocus = false" to avoid painting in selection colors when focused
|
||||||
|
super.paintCurrentValue( g, bounds, false );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class FlatArrowButton ----------------------------------------------
|
//---- class FlatArrowButton ----------------------------------------------
|
||||||
|
|
||||||
private static class FlatArrowButton
|
private static class FlatArrowButton
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
*.selectionBackground=4B6EAF
|
*.selectionBackground=4B6EAF
|
||||||
*.selectionForeground=@foreground
|
*.selectionForeground=@foreground
|
||||||
*.disabledBackground=@background
|
*.disabledBackground=@background
|
||||||
|
*.disabledForeground=@disabledText
|
||||||
*.disabledText=@disabledText
|
*.disabledText=@disabledText
|
||||||
|
|
||||||
|
|
||||||
@@ -99,11 +100,6 @@ Component.focusedBorderColor=466d94
|
|||||||
Component.focusColor=3d6185
|
Component.focusColor=3d6185
|
||||||
|
|
||||||
|
|
||||||
#---- Label ----
|
|
||||||
|
|
||||||
Label.disabledForeground=@disabledText
|
|
||||||
|
|
||||||
|
|
||||||
#---- ProgressBar ----
|
#---- ProgressBar ----
|
||||||
|
|
||||||
ProgressBar.background=555555
|
ProgressBar.background=555555
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
*.selectionBackground=4A6EB7
|
*.selectionBackground=4A6EB7
|
||||||
*.selectionForeground=ffffff
|
*.selectionForeground=ffffff
|
||||||
*.disabledBackground=@background
|
*.disabledBackground=@background
|
||||||
|
*.disabledForeground=@disabledText
|
||||||
*.disabledText=@disabledText
|
*.disabledText=@disabledText
|
||||||
|
|
||||||
|
|
||||||
@@ -99,11 +100,6 @@ Component.focusedBorderColor=87afda
|
|||||||
Component.focusColor=97c3f3
|
Component.focusColor=97c3f3
|
||||||
|
|
||||||
|
|
||||||
#---- Label ----
|
|
||||||
|
|
||||||
Label.disabledForeground=@disabledText
|
|
||||||
|
|
||||||
|
|
||||||
#---- ProgressBar ----
|
#---- ProgressBar ----
|
||||||
|
|
||||||
ProgressBar.background=c4c4c4
|
ProgressBar.background=c4c4c4
|
||||||
|
|||||||
@@ -23,10 +23,16 @@
|
|||||||
|
|
||||||
*.background=ccffcc
|
*.background=ccffcc
|
||||||
*.foreground=ff0000
|
*.foreground=ff0000
|
||||||
|
*.textBackground=ccffcc
|
||||||
|
*.textForeground=ff0000
|
||||||
|
*.caretForeground=0000ff
|
||||||
*.inactiveBackground=f0f0f0
|
*.inactiveBackground=f0f0f0
|
||||||
*.disabledBackground=e0e0e0
|
|
||||||
*.disabledText=000088
|
|
||||||
*.inactiveForeground=000088
|
*.inactiveForeground=000088
|
||||||
|
*.selectionBackground=4B6EAF
|
||||||
|
*.selectionForeground=00ff00
|
||||||
|
*.disabledBackground=e0e0e0
|
||||||
|
*.disabledForeground=000088
|
||||||
|
*.disabledText=000088
|
||||||
|
|
||||||
|
|
||||||
#---- Button ----
|
#---- Button ----
|
||||||
|
|||||||
Reference in New Issue
Block a user