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.Graphics2D;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
@@ -33,6 +34,7 @@ import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
@@ -80,11 +82,11 @@ public class FlatComboBoxUI
|
||||
String propertyName = e.getPropertyName();
|
||||
|
||||
if( editor != null &&
|
||||
((source == comboBox && propertyName == "background") ||
|
||||
((source == comboBox && (propertyName == "background" || propertyName == "foreground")) ||
|
||||
(source == editor && propertyName == "enabled")) )
|
||||
{
|
||||
// fix editor component background color
|
||||
updateEditorBackground();
|
||||
// fix editor component colors
|
||||
updateEditorColors();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -94,13 +96,19 @@ public class FlatComboBoxUI
|
||||
protected void configureEditor() {
|
||||
super.configureEditor();
|
||||
|
||||
updateEditorBackground();
|
||||
updateEditorColors();
|
||||
}
|
||||
|
||||
private void updateEditorBackground() {
|
||||
editor.setBackground( editor.isEnabled()
|
||||
private void updateEditorColors() {
|
||||
boolean enabled = editor.isEnabled();
|
||||
editor.setBackground( enabled
|
||||
? comboBox.getBackground()
|
||||
: 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
|
||||
@@ -149,6 +157,12 @@ public class FlatComboBoxUI
|
||||
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 ----------------------------------------------
|
||||
|
||||
private static class FlatArrowButton
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
*.selectionBackground=4B6EAF
|
||||
*.selectionForeground=@foreground
|
||||
*.disabledBackground=@background
|
||||
*.disabledForeground=@disabledText
|
||||
*.disabledText=@disabledText
|
||||
|
||||
|
||||
@@ -99,11 +100,6 @@ Component.focusedBorderColor=466d94
|
||||
Component.focusColor=3d6185
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
Label.disabledForeground=@disabledText
|
||||
|
||||
|
||||
#---- ProgressBar ----
|
||||
|
||||
ProgressBar.background=555555
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
*.selectionBackground=4A6EB7
|
||||
*.selectionForeground=ffffff
|
||||
*.disabledBackground=@background
|
||||
*.disabledForeground=@disabledText
|
||||
*.disabledText=@disabledText
|
||||
|
||||
|
||||
@@ -99,11 +100,6 @@ Component.focusedBorderColor=87afda
|
||||
Component.focusColor=97c3f3
|
||||
|
||||
|
||||
#---- Label ----
|
||||
|
||||
Label.disabledForeground=@disabledText
|
||||
|
||||
|
||||
#---- ProgressBar ----
|
||||
|
||||
ProgressBar.background=c4c4c4
|
||||
|
||||
@@ -23,10 +23,16 @@
|
||||
|
||||
*.background=ccffcc
|
||||
*.foreground=ff0000
|
||||
*.textBackground=ccffcc
|
||||
*.textForeground=ff0000
|
||||
*.caretForeground=0000ff
|
||||
*.inactiveBackground=f0f0f0
|
||||
*.disabledBackground=e0e0e0
|
||||
*.disabledText=000088
|
||||
*.inactiveForeground=000088
|
||||
*.selectionBackground=4B6EAF
|
||||
*.selectionForeground=00ff00
|
||||
*.disabledBackground=e0e0e0
|
||||
*.disabledForeground=000088
|
||||
*.disabledText=000088
|
||||
|
||||
|
||||
#---- Button ----
|
||||
|
||||
Reference in New Issue
Block a user