diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java index fc80000f..6419ab92 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java @@ -80,6 +80,10 @@ public class FlatArrowButton } } + protected boolean isHover() { + return hover; + } + public int getXOffset() { return xOffset; } @@ -116,7 +120,7 @@ public class FlatArrowButton boolean enabled = isEnabled(); // paint hover background - if( enabled && hover && hoverBackground != null ) { + if( enabled && isHover() && hoverBackground != null ) { g.setColor( hoverBackground ); g.fillRect( 0, 0, width, height ); } @@ -139,7 +143,7 @@ public class FlatArrowButton // paint arrow g.setColor( enabled - ? (hover && hoverForeground != null ? hoverForeground : foreground) + ? (isHover() && hoverForeground != null ? hoverForeground : foreground) : disabledForeground ); g.translate( x, y ); Shape arrowShape = createArrowShape( direction, chevron, w, h ); 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 8b95f8e5..badf24be 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 @@ -29,6 +29,7 @@ import java.awt.Rectangle; import java.awt.Shape; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.MouseListener; import java.awt.geom.Rectangle2D; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -88,10 +89,35 @@ public class FlatComboBoxUI protected Color buttonDisabledArrowColor; protected Color buttonHoverArrowColor; + private MouseListener hoverListener; + private boolean hover; + public static ComponentUI createUI( JComponent c ) { return new FlatComboBoxUI(); } + @Override + protected void installListeners() { + super.installListeners(); + + hoverListener = new FlatUIUtils.HoverListener( null, h -> { + if( !comboBox.isEditable() ) { + hover = h; + if( arrowButton != null ) + arrowButton.repaint(); + } + } ); + comboBox.addMouseListener( hoverListener ); + } + + @Override + protected void uninstallListeners() { + super.uninstallListeners(); + + comboBox.removeMouseListener( hoverListener ); + hoverListener = null; + } + @Override protected void installDefaults() { super.installDefaults(); @@ -228,7 +254,13 @@ public class FlatComboBoxUI @Override protected JButton createArrowButton() { return new FlatArrowButton( SwingConstants.SOUTH, arrowType, buttonArrowColor, - buttonDisabledArrowColor, buttonHoverArrowColor, null ); + buttonDisabledArrowColor, buttonHoverArrowColor, null ) + { + @Override + protected boolean isHover() { + return super.isHover() || (!comboBox.isEditable() ? hover : false); + } + }; } @Override