ComboBox and Spinner: support changing arrow button style (issue #114)

This commit is contained in:
Karl Tauber
2020-06-19 18:12:23 +02:00
parent 84cc86bef7
commit 262ae7865b
6 changed files with 27 additions and 7 deletions

View File

@@ -12,6 +12,10 @@ FlatLaf Change Log
- ScrollBar: Support pressed track, thumb and button colors (use UI values - ScrollBar: Support pressed track, thumb and button colors (use UI values
`ScrollBar.pressedTrackColor`, `ScrollBar.pressedThumbColor` and `ScrollBar.pressedTrackColor`, `ScrollBar.pressedThumbColor` and
`ScrollBar.pressedButtonBackground`). (issue #115) `ScrollBar.pressedButtonBackground`). (issue #115)
- ComboBox: Support changing arrow button style (set UI value
`ComboBox.buttonStyle` to `auto` (default), `button` or `none`). (issue #114)
- Spinner: Support changing arrows button style (set UI value
`Spinner.buttonStyle` to `button` (default) or `none`).
- TableHeader: Support top/bottom/left positioned sort arrow when using - TableHeader: Support top/bottom/left positioned sort arrow when using
[Glazed Lists](https://github.com/glazedlists/glazedlists). (issue #113) [Glazed Lists](https://github.com/glazedlists/glazedlists). (issue #113)

View File

@@ -80,6 +80,7 @@ import com.formdev.flatlaf.util.UIScale;
* *
* @uiDefault ComboBox.minimumWidth int * @uiDefault ComboBox.minimumWidth int
* @uiDefault ComboBox.editorColumns int * @uiDefault ComboBox.editorColumns int
* @uiDefault ComboBox.buttonStyle String auto (default), button or none
* @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color * @uiDefault Component.borderColor Color
@@ -100,6 +101,7 @@ public class FlatComboBoxUI
{ {
protected int minimumWidth; protected int minimumWidth;
protected int editorColumns; protected int editorColumns;
protected String buttonStyle;
protected String arrowType; protected String arrowType;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
protected Color borderColor; protected Color borderColor;
@@ -154,6 +156,7 @@ public class FlatComboBoxUI
minimumWidth = UIManager.getInt( "ComboBox.minimumWidth" ); minimumWidth = UIManager.getInt( "ComboBox.minimumWidth" );
editorColumns = UIManager.getInt( "ComboBox.editorColumns" ); editorColumns = UIManager.getInt( "ComboBox.editorColumns" );
buttonStyle = UIManager.getString( "ComboBox.buttonStyle" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" ); borderColor = UIManager.getColor( "Component.borderColor" );
@@ -350,6 +353,7 @@ public class FlatComboBoxUI
int height = c.getHeight(); int height = c.getHeight();
int arrowX = arrowButton.getX(); int arrowX = arrowButton.getX();
int arrowWidth = arrowButton.getWidth(); int arrowWidth = arrowButton.getWidth();
boolean paintButton = (comboBox.isEditable() || "button".equals( buttonStyle )) && !"none".equals( buttonStyle );
boolean enabled = comboBox.isEnabled(); boolean enabled = comboBox.isEnabled();
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight(); boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
@@ -361,7 +365,7 @@ public class FlatComboBoxUI
// paint arrow button background // paint arrow button background
if( enabled ) { if( enabled ) {
g2.setColor( comboBox.isEditable() ? buttonEditableBackground : buttonBackground ); g2.setColor( paintButton ? buttonEditableBackground : buttonBackground );
Shape oldClip = g2.getClip(); Shape oldClip = g2.getClip();
if( isLeftToRight ) if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height ); g2.clipRect( arrowX, 0, width - arrowX, height );
@@ -372,7 +376,7 @@ public class FlatComboBoxUI
} }
// paint vertical line between value and arrow button // paint vertical line between value and arrow button
if( comboBox.isEditable() ) { if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor ); g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f ); float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw; float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;

View File

@@ -58,6 +58,7 @@ import com.formdev.flatlaf.FlatClientProperties;
* <!-- FlatSpinnerUI --> * <!-- FlatSpinnerUI -->
* *
* @uiDefault Component.minimumWidth int * @uiDefault Component.minimumWidth int
* @uiDefault Spinner.buttonStyle String button (default) or none
* @uiDefault Component.arrowType String triangle (default) or chevron * @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean * @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color * @uiDefault Component.borderColor Color
@@ -78,6 +79,7 @@ public class FlatSpinnerUI
private Handler handler; private Handler handler;
protected int minimumWidth; protected int minimumWidth;
protected String buttonStyle;
protected String arrowType; protected String arrowType;
protected boolean isIntelliJTheme; protected boolean isIntelliJTheme;
protected Color borderColor; protected Color borderColor;
@@ -101,6 +103,7 @@ public class FlatSpinnerUI
LookAndFeel.installProperty( spinner, "opaque", false ); LookAndFeel.installProperty( spinner, "opaque", false );
minimumWidth = UIManager.getInt( "Component.minimumWidth" ); minimumWidth = UIManager.getInt( "Component.minimumWidth" );
buttonStyle = UIManager.getString( "Spinner.buttonStyle" );
arrowType = UIManager.getString( "Component.arrowType" ); arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" ); isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" ); borderColor = UIManager.getColor( "Component.borderColor" );
@@ -258,6 +261,7 @@ public class FlatSpinnerUI
Component nextButton = getHandler().nextButton; Component nextButton = getHandler().nextButton;
int arrowX = nextButton.getX(); int arrowX = nextButton.getX();
int arrowWidth = nextButton.getWidth(); int arrowWidth = nextButton.getWidth();
boolean paintButton = !"none".equals( buttonStyle );
boolean enabled = spinner.isEnabled(); boolean enabled = spinner.isEnabled();
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight(); boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
@@ -268,7 +272,7 @@ public class FlatSpinnerUI
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
// paint arrow buttons background // paint arrow buttons background
if( enabled ) { if( paintButton && enabled ) {
g2.setColor( buttonBackground ); g2.setColor( buttonBackground );
Shape oldClip = g2.getClip(); Shape oldClip = g2.getClip();
if( isLeftToRight ) if( isLeftToRight )
@@ -280,10 +284,12 @@ public class FlatSpinnerUI
} }
// paint vertical line between value and arrow buttons // paint vertical line between value and arrow buttons
g2.setColor( enabled ? borderColor : disabledBorderColor ); if( paintButton ) {
float lw = scale( 1f ); g2.setColor( enabled ? borderColor : disabledBorderColor );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw; float lw = scale( 1f );
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) ); float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );
}
paint( g, c ); paint( g, c );
} }

View File

@@ -181,6 +181,7 @@ ComboBox.padding=2,6,2,6
ComboBox.minimumWidth=72 ComboBox.minimumWidth=72
ComboBox.editorColumns=0 ComboBox.editorColumns=0
[mac]ComboBox.showPopupOnNavigation=true [mac]ComboBox.showPopupOnNavigation=true
ComboBox.buttonStyle=auto
#---- Component ---- #---- Component ----
@@ -478,6 +479,7 @@ Spinner.buttonDisabledArrowColor=$ComboBox.buttonDisabledArrowColor
Spinner.buttonHoverArrowColor=$ComboBox.buttonHoverArrowColor Spinner.buttonHoverArrowColor=$ComboBox.buttonHoverArrowColor
Spinner.padding=@textComponentMargin Spinner.padding=@textComponentMargin
Spinner.editorBorderPainted=false Spinner.editorBorderPainted=false
Spinner.buttonStyle=button
#---- SplitPane ---- #---- SplitPane ----

View File

@@ -189,6 +189,7 @@ ComboBox.buttonEditableBackground #404445 javax.swing.plaf.ColorUIResource [U
ComboBox.buttonHighlight #242424 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHighlight #242424 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonShadow #646464 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonShadow #646464 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonStyle auto
ComboBox.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI]
ComboBox.editorColumns 0 ComboBox.editorColumns 0
@@ -850,6 +851,7 @@ Spinner.buttonArrowColor #9a9da1 javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonBackground #404445 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonBackground #404445 javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonDisabledArrowColor #585858 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonDisabledArrowColor #585858 javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI] Spinner.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonStyle button
Spinner.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI] Spinner.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
Spinner.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] Spinner.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI]
Spinner.editorAlignment 11 Spinner.editorAlignment 11

View File

@@ -193,6 +193,7 @@ ComboBox.buttonEditableBackground #fafafa javax.swing.plaf.ColorUIResource [U
ComboBox.buttonHighlight #ffffff javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHighlight #ffffff javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonShadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonShadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonStyle auto
ComboBox.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
ComboBox.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
ComboBox.editorColumns 0 ComboBox.editorColumns 0
@@ -855,6 +856,7 @@ Spinner.buttonArrowColor #666666 javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonBackground #fafafa javax.swing.plaf.ColorUIResource [UI] Spinner.buttonBackground #fafafa javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonDisabledArrowColor #ababab javax.swing.plaf.ColorUIResource [UI] Spinner.buttonDisabledArrowColor #ababab javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI]
Spinner.buttonStyle button
Spinner.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI] Spinner.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
Spinner.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] Spinner.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI]
Spinner.editorAlignment 11 Spinner.editorAlignment 11