title: Setting component focus in JOptionPane.showOptionDialog()
body: <p>In order to have custom button captions in an input dialog, I created the following code:</p>
  
  <pre><code>String key = null;
  JTextField txtKey = new JTextField();        
  int answerKey = JOptionPane.showOptionDialog(this, new Object[] {pleaseEnterTheKey, txtKey}, decryptionKey, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {okCaption, cancelCaption}, okCaption);        
  if (answerKey == JOptionPane.OK_OPTION &amp;&amp; txtKey.getText() != null) {
    key = txtKey.getText();
  }
  </code></pre>
  
  <p>How can I <strong>move the focus</strong> (cursor) to the text field as the dialog is displayed?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This does not work for me, I mean the textfield has no focus:
  OS: Fedora - Gnome</p>
  
  <pre><code>public class Test {
    public static void main(String[] args) {
      String key = null;
      JTextField txtKey = new JTextField();
      txtKey.addAncestorListener(new RequestFocusListener());
      int answerKey = JOptionPane.showOptionDialog(null, new Object[]{"Please enter the key:", txtKey}, "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OKKK", "CANCELLLL"}, "OKKK");
      if (answerKey == JOptionPane.OK_OPTION &amp;&amp; txtKey.getText() != null) {
        key = txtKey.getText();
      }
    }
  }
  </code></pre>