diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 30704fa0..3b0749e6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -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 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 2c3cc326..cebceed4 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -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 diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index 690a87fc..4b4eb335 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -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 diff --git a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties index 880b797b..824185ab 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -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 ----