- repaint if JSpinner component gained/lost focus
- paint focus border if JSpinner component is focused
- if spinner gained focus, transfer it to the editor text field
This commit is contained in:
Karl Tauber
2020-05-24 14:44:36 +02:00
parent 566e42cc40
commit e9e1e350eb
2 changed files with 13 additions and 1 deletions

View File

@@ -178,6 +178,9 @@ public class FlatBorder
Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
} else if( c instanceof JSpinner ) {
if( FlatUIUtils.isPermanentFocusOwner( c ) )
return true;
JComponent editor = ((JSpinner)c).getEditor();
if( editor instanceof JSpinner.DefaultEditor ) {
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();

View File

@@ -141,6 +141,7 @@ public class FlatSpinnerUI
super.installListeners();
addEditorFocusListener( spinner.getEditor() );
spinner.addFocusListener( getHandler() );
spinner.addPropertyChangeListener( getHandler() );
}
@@ -149,6 +150,7 @@ public class FlatSpinnerUI
super.uninstallListeners();
removeEditorFocusListener( spinner.getEditor() );
spinner.removeFocusListener( getHandler() );
spinner.removePropertyChangeListener( getHandler() );
handler = null;
@@ -206,7 +208,7 @@ public class FlatSpinnerUI
}
}
private JTextField getEditorTextField( JComponent editor ) {
private static JTextField getEditorTextField( JComponent editor ) {
return editor instanceof JSpinner.DefaultEditor
? ((JSpinner.DefaultEditor)editor).getTextField()
: null;
@@ -379,6 +381,13 @@ public class FlatSpinnerUI
@Override
public void focusGained( FocusEvent e ) {
spinner.repaint();
// if spinner gained focus, transfer it to the editor text field
if( e.getComponent() == spinner ) {
JTextField textField = getEditorTextField( spinner.getEditor() );
if( textField != null )
textField.requestFocusInWindow();
}
}
@Override