mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Spinner:
- 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:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user