mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
ComboBox (editable) and Spinner: increased size of internal text field to the component border so that it behaves like plain text field (issue #330)
This commit is contained in:
@@ -133,6 +133,8 @@ public class FlatComboBoxUI
|
||||
|
||||
protected Color popupBackground;
|
||||
|
||||
protected Insets paddingUnscaled;
|
||||
|
||||
private MouseListener hoverListener;
|
||||
protected boolean hover;
|
||||
protected boolean pressed;
|
||||
@@ -223,7 +225,8 @@ public class FlatComboBoxUI
|
||||
comboBox.setMaximumRowCount( maximumRowCount );
|
||||
|
||||
// scale
|
||||
padding = UIScale.scale( padding );
|
||||
paddingUnscaled = padding;
|
||||
padding = UIScale.scale( paddingUnscaled );
|
||||
|
||||
MigLayoutVisualPadding.install( comboBox );
|
||||
}
|
||||
@@ -276,11 +279,6 @@ public class FlatComboBoxUI
|
||||
editor.setBounds( rectangleForCurrentValue() );
|
||||
}
|
||||
}
|
||||
|
||||
if( editor != null && padding != null ) {
|
||||
// fix editor bounds by subtracting padding
|
||||
editor.setBounds( FlatUIUtils.subtractInsets( editor.getBounds(), padding ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -361,9 +359,16 @@ public class FlatComboBoxUI
|
||||
protected void configureEditor() {
|
||||
super.configureEditor();
|
||||
|
||||
// remove default text field border from editor
|
||||
if( editor instanceof JTextField && ((JTextField)editor).getBorder() instanceof FlatTextBorder )
|
||||
((JTextField)editor).setBorder( BorderFactory.createEmptyBorder() );
|
||||
if( editor instanceof JTextField ) {
|
||||
JTextField textField = (JTextField) editor;
|
||||
|
||||
// remove default text field border from editor
|
||||
if( textField.getBorder() instanceof FlatTextBorder )
|
||||
textField.setBorder( BorderFactory.createEmptyBorder() );
|
||||
|
||||
// editor padding
|
||||
textField.putClientProperty( FlatClientProperties.TEXT_FIELD_PADDING, paddingUnscaled );
|
||||
}
|
||||
|
||||
// explicitly make non-opaque
|
||||
if( editor instanceof JComponent )
|
||||
@@ -548,6 +553,9 @@ public class FlatComboBoxUI
|
||||
ListCellRenderer<Object> renderer = comboBox.getRenderer();
|
||||
uninstallCellPaddingBorder( renderer );
|
||||
|
||||
// update padding
|
||||
padding = UIScale.scale( paddingUnscaled );
|
||||
|
||||
Dimension displaySize = super.getDisplaySize();
|
||||
|
||||
// recalculate width without hardcoded 100 under special conditions
|
||||
|
||||
@@ -123,9 +123,6 @@ public class FlatSpinnerUI
|
||||
buttonPressedArrowColor = UIManager.getColor( "Spinner.buttonPressedArrowColor" );
|
||||
padding = UIManager.getInsets( "Spinner.padding" );
|
||||
|
||||
// scale
|
||||
padding = scale( padding );
|
||||
|
||||
MigLayoutVisualPadding.install( spinner );
|
||||
}
|
||||
|
||||
@@ -184,6 +181,7 @@ public class FlatSpinnerUI
|
||||
if( textField != null )
|
||||
textField.setOpaque( false );
|
||||
|
||||
updateEditorPadding();
|
||||
updateEditorColors();
|
||||
return editor;
|
||||
}
|
||||
@@ -194,6 +192,8 @@ public class FlatSpinnerUI
|
||||
|
||||
removeEditorFocusListener( oldEditor );
|
||||
addEditorFocusListener( newEditor );
|
||||
|
||||
updateEditorPadding();
|
||||
updateEditorColors();
|
||||
}
|
||||
|
||||
@@ -209,6 +209,12 @@ public class FlatSpinnerUI
|
||||
textField.removeFocusListener( getHandler() );
|
||||
}
|
||||
|
||||
private void updateEditorPadding() {
|
||||
JTextField textField = getEditorTextField( spinner.getEditor() );
|
||||
if( textField != null )
|
||||
textField.putClientProperty( FlatClientProperties.TEXT_FIELD_PADDING, padding );
|
||||
}
|
||||
|
||||
private void updateEditorColors() {
|
||||
JTextField textField = getEditorTextField( spinner.getEditor() );
|
||||
if( textField != null ) {
|
||||
@@ -373,6 +379,7 @@ public class FlatSpinnerUI
|
||||
@Override
|
||||
public Dimension preferredLayoutSize( Container parent ) {
|
||||
Insets insets = parent.getInsets();
|
||||
Insets padding = scale( FlatSpinnerUI.this.padding );
|
||||
Dimension editorSize = (editor != null) ? editor.getPreferredSize() : new Dimension( 0, 0 );
|
||||
|
||||
// the arrows width is the same as the inner height so that the arrows area is square
|
||||
@@ -397,7 +404,7 @@ public class FlatSpinnerUI
|
||||
|
||||
if( nextButton == null && previousButton == null ) {
|
||||
if( editor != null )
|
||||
editor.setBounds( FlatUIUtils.subtractInsets( r, padding ) );
|
||||
editor.setBounds( r );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -417,7 +424,7 @@ public class FlatSpinnerUI
|
||||
}
|
||||
|
||||
if( editor != null )
|
||||
editor.setBounds( FlatUIUtils.subtractInsets( editorRect, padding ) );
|
||||
editor.setBounds( editorRect );
|
||||
|
||||
int nextHeight = (buttonsRect.height / 2) + (buttonsRect.height % 2); // round up
|
||||
if( nextButton != null )
|
||||
|
||||
Reference in New Issue
Block a user