List of usage examples for javax.swing JSpinner addFocusListener
public synchronized void addFocusListener(FocusListener l)
From source file:Main.java
/** * Installs a workaround for bug #4699955 in a JSpinner. * /*from w w w. j a v a 2 s. c o m*/ * @param spinner * The spinner to fix */ public static void installSpinnerBugWorkaround(final JSpinner spinner) { ((DefaultEditor) spinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { if (e.getSource() instanceof JTextComponent) { final JTextComponent text = ((JTextComponent) e.getSource()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { text.selectAll(); } }); } } }); spinner.addFocusListener(new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { if (e.getSource() instanceof JSpinner) { final JTextComponent text = ((DefaultEditor) ((JSpinner) e.getSource()).getEditor()) .getTextField(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { text.requestFocus(); } }); } } }); }
From source file:Main.java
/** * Installs a workaround for bug #4699955 in a JSpinner. * * @param spinner//from www . ja v a2s . c o m * The spinner to fix */ public static void installSpinnerBugWorkaround(final JSpinner spinner) { ((DefaultEditor) spinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { if (e.getSource() instanceof JTextComponent) { final JTextComponent text = (JTextComponent) e.getSource(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { text.selectAll(); } }); } } }); spinner.addFocusListener(new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { if (e.getSource() instanceof JSpinner) { final JTextComponent text = ((DefaultEditor) ((JSpinner) e.getSource()).getEditor()) .getTextField(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { text.requestFocus(); } }); } } }); }