title: Selecting / highlighting text in a JTextArea belonging to a JOptionPane
body: <p>My problem is the following:<br><br> In my application the user clicks a button which brings up a dialog box (a custom jOptionPane). This dialog contains a JTextArea in which the user will type a response, which will then be processed by the application, however I would like this JTextArea (which will hold the user's input and currently contains example text like "Write your answer here") to be automatically highlighted.</p>
  
  <p>I can do this normally, by calling requestFocusInWindow() followed by selectAll() on the JTextArea however there seems to be a problem when this is done using a JOptionPane which I'm guessing is to do with the fact that the focus cannot shift to the JTextArea successfully.</p>
  
  <p>I've made a SSCCE to demonstrate this clearly, and hopefully get an answer from one of you guys as to how I can make this possible. Thanks in advance!
  <br><br>
  <strong>Class 1/2 : Main</strong><br></p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  
  public class Main extends JFrame{
  
  
      public static void main(String[] args) {
          Main main = new Main();
          main.go();
      }
  
      private void go() {
          JPanel background = new JPanel();
          JPanel mainPanel = new ExtraPanel();
          ((ExtraPanel) mainPanel).setupPanel();
          JButton testButton = new JButton("Test the jOptionPane");
          testButton.addActionListener(new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent arg0) {
                  optionPaneTest();
              }
          });
          background.add(mainPanel);
          background.add(testButton);
          getContentPane().add(background);
          pack();
          setVisible(true);
  
      }
  
      private void optionPaneTest() {
          JPanel testPanel = new ExtraPanel();
          ((ExtraPanel) testPanel).setupPanel();
          int result = JOptionPane.showConfirmDialog(null, testPanel,
                  "This is a test", JOptionPane.OK_CANCEL_OPTION);
      }
  }
  </code></pre>
  
  <p>-----------------------------------------------------------------------------<br> <strong>Class 2/2 : ExtraPanel</strong><br></p>
  
  <pre><code>import javax.swing.JPanel;
  import javax.swing.JTextArea;
  
  public class ExtraPanel extends JPanel{
  
      public void setupPanel() {
          JTextArea textArea = new JTextArea();
          textArea.setText("Write your response here");
          textArea.requestFocusInWindow();
          textArea.selectAll();
          add(textArea);
      }
  
  }
  </code></pre>