title: JDialog lets main application lose focus
body: <p>I wonder why my JDialog pushes my main application into background. That means if the JDialog will be shown and the user clicks "OK" or "CANCEL" the main application looses its focus and will be pushed into the background.</p>
  
  <p>After my investigation I found out, that this behaviour only happens if I disable my main frame for the time I show the JDialog. </p>
  
  <p>This behaviour could be reproduced with the following code:</p>
  
  <p><pre><code>
  import java.awt.Component;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;</p>
  
  <p>import javax.swing.JButton;
  import javax.swing.JDialog;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;</p>
  
  <p>public class FocusTest {</p>
  
  <pre><code>private JFrame frame;
  
  public FocusTest() {
      frame = new JFrame();
      frame.setSize(200,200);
      JButton btn = new JButton("Open Dialog");
      btn.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              callDialog(null, "title", "message");
          }
      });
      frame.add(btn);
      frame.setVisible(true);
  }
  
  private void callDialog(Component parent, String title, String message) {
      frame.setEnabled(false);
      Thread t1 = new Thread(new Runnable() {
          public void run() {
              JOptionPane optionPane = new JOptionPane("",
                      JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
                  JDialog dialog = optionPane.createDialog(null, "");
                  dialog.setVisible(true);
                  frame.setEnabled(true);
          }
      });
      t1.start();
  }
  
  public static void main(String[] args) {
      new FocusTest();
  }
  </code></pre>
  
  <p>}
  </pre></code></p>
  
  <p>How can I avoid that the main application looses its focus? (without enabling the main frame)</p>