mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
ComboBox: if not editable, then hover highlight arrow even if mouse is not in arrow button
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user