- support ComboBox.padding
- fixed updating of Spinner.padding
This commit is contained in:
Karl Tauber
2021-07-05 22:36:57 +02:00
parent 4a8207f367
commit 84f7e244f2
3 changed files with 16 additions and 2 deletions

View File

@@ -447,10 +447,15 @@ public class FlatComboBoxUI
* @since TODO * @since TODO
*/ */
protected void applyStyle( Object style ) { protected void applyStyle( Object style ) {
Insets oldPadding = padding;
int oldEditorColumns = editorColumns; int oldEditorColumns = editorColumns;
oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty ); oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
if( !padding.equals( oldPadding ) ) {
paddingBorder.padding = padding;
updateEditorPadding();
}
if( arrowButton instanceof FlatComboBoxButton ) if( arrowButton instanceof FlatComboBoxButton )
((FlatComboBoxButton)arrowButton).updateStyle(); ((FlatComboBoxButton)arrowButton).updateStyle();
if( popup instanceof FlatComboPopup ) if( popup instanceof FlatComboPopup )
@@ -463,6 +468,13 @@ public class FlatComboBoxUI
* @since TODO * @since TODO
*/ */
protected Object applyStyleProperty( String key, Object value ) { protected Object applyStyleProperty( String key, Object value ) {
// BasicComboBoxUI
if( key.equals( "padding" ) ) {
Object oldValue = padding;
padding = (Insets) value;
return oldValue;
}
if( borderShared == null ) if( borderShared == null )
borderShared = new AtomicBoolean( true ); borderShared = new AtomicBoolean( true );
return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared ); return FlatStyleSupport.applyToAnnotatedObjectOrBorder( this, key, value, comboBox, borderShared );
@@ -834,7 +846,7 @@ public class FlatComboBoxUI
private static class CellPaddingBorder private static class CellPaddingBorder
extends AbstractBorder extends AbstractBorder
{ {
private final Insets padding; private Insets padding;
private JComponent rendererComponent; private JComponent rendererComponent;
private Border rendererBorder; private Border rendererBorder;

View File

@@ -192,6 +192,7 @@ public class FlatSpinnerUI
*/ */
protected void applyStyle( Object style ) { protected void applyStyle( Object style ) {
oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty ); oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );
updateEditorPadding();
updateArrowButtonsStyle(); updateArrowButtonsStyle();
} }
@@ -442,7 +443,6 @@ public class FlatSpinnerUI
public void layoutContainer( Container parent ) { public void layoutContainer( Container parent ) {
Dimension size = parent.getSize(); Dimension size = parent.getSize();
Insets insets = parent.getInsets(); Insets insets = parent.getInsets();
Insets padding = scale( FlatSpinnerUI.this.padding );
Rectangle r = FlatUIUtils.subtractInsets( new Rectangle( size ), insets ); Rectangle r = FlatUIUtils.subtractInsets( new Rectangle( size ), insets );
if( nextButton == null && previousButton == null ) { if( nextButton == null && previousButton == null ) {

View File

@@ -149,6 +149,8 @@ public class TestFlatStyling
JComboBox<Object> c = new JComboBox<>(); JComboBox<Object> c = new JComboBox<>();
FlatComboBoxUI ui = (FlatComboBoxUI) c.getUI(); FlatComboBoxUI ui = (FlatComboBoxUI) c.getUI();
ui.applyStyle( "padding: 1,2,3,4" );
ui.applyStyle( "minimumWidth: 100" ); ui.applyStyle( "minimumWidth: 100" );
ui.applyStyle( "editorColumns: 10" ); ui.applyStyle( "editorColumns: 10" );
ui.applyStyle( "buttonStyle: auto" ); ui.applyStyle( "buttonStyle: auto" );