title: Make JSpinner Select Text When Focused
body: <p>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. Unfortunately, I can't get the behavior to work and instead, it just inserts the cursor in the text without selecting what is already there.</p>
  
  <p>I have tried adding a focus Listener to both the JSpinner itself and the text area itself, via <code>((DefaultEditor) this.getEditor()).getTextField()</code>, yet neither of these seem to have the intended effect. My code (for the JSpinner itself) is as follows:</p>
  
  <pre><code>spinner.addFocusListener(new FocusAdapter(){
              @Override
              public void focusGained(FocusEvent e) {
                  ((DefaultEditor) ((JSpinner) e.getSource()).getEditor()).getTextField().selectAll();
              }
          }); 
  </code></pre>
  
  <p>I'm not sure what the problem is. If it matters, I'm running Mac OS 10.7.5 and Java 6u43.</p>
  
  <p>EDIT: I put a <code>System.out.println</code> right at the beginning of the focusGained method and discovered that it was never called. So it looks like getting focus on the JSpinner isn't registering. Again, I tried putting the focusAdpater both on the spinner and on the text field (not at the same time though).</p>