I would like to change the behavior of a JSpinner so that when you click on the text, it selects it. This makes it easier to replace the field with the value that you want.
Don't know about a Mac but I've used this code on Windows:
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor)spinner.getEditor();
JTextField textField = editor.getTextField();
textField.addFocusListener( new FocusAdapter()
{
public void focusGained(final FocusEvent e)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
JTextField tf = (JTextField)e.getSource();
tf.selectAll();
}
});
}
});
I've also used this code for selecting text on a JFormattedTextField.