mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 22:40:53 +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();
|
Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
|
||||||
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
|
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
|
||||||
} else if( c instanceof JSpinner ) {
|
} else if( c instanceof JSpinner ) {
|
||||||
|
if( FlatUIUtils.isPermanentFocusOwner( c ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
JComponent editor = ((JSpinner)c).getEditor();
|
JComponent editor = ((JSpinner)c).getEditor();
|
||||||
if( editor instanceof JSpinner.DefaultEditor ) {
|
if( editor instanceof JSpinner.DefaultEditor ) {
|
||||||
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
|
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ public class FlatSpinnerUI
|
|||||||
super.installListeners();
|
super.installListeners();
|
||||||
|
|
||||||
addEditorFocusListener( spinner.getEditor() );
|
addEditorFocusListener( spinner.getEditor() );
|
||||||
|
spinner.addFocusListener( getHandler() );
|
||||||
spinner.addPropertyChangeListener( getHandler() );
|
spinner.addPropertyChangeListener( getHandler() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +150,7 @@ public class FlatSpinnerUI
|
|||||||
super.uninstallListeners();
|
super.uninstallListeners();
|
||||||
|
|
||||||
removeEditorFocusListener( spinner.getEditor() );
|
removeEditorFocusListener( spinner.getEditor() );
|
||||||
|
spinner.removeFocusListener( getHandler() );
|
||||||
spinner.removePropertyChangeListener( getHandler() );
|
spinner.removePropertyChangeListener( getHandler() );
|
||||||
|
|
||||||
handler = null;
|
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
|
return editor instanceof JSpinner.DefaultEditor
|
||||||
? ((JSpinner.DefaultEditor)editor).getTextField()
|
? ((JSpinner.DefaultEditor)editor).getTextField()
|
||||||
: null;
|
: null;
|
||||||
@@ -379,6 +381,13 @@ public class FlatSpinnerUI
|
|||||||
@Override
|
@Override
|
||||||
public void focusGained( FocusEvent e ) {
|
public void focusGained( FocusEvent e ) {
|
||||||
spinner.repaint();
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user