title: How to prevent blank JOptionPane windows
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13093499/how-do-i-run-joptionpane-on-edt">How do I run JOptionPane on EDT?</a>  </p>
  </blockquote>
  
  
  
  <p>At seemingly random times (i.e. if the program is run enough times) a <code>JOptionPane</code> window I have programmed will display a blank window the close &amp; ok buttons are there but none of the text I coded. This seems to occur in any program written with <code>JOptionPane</code> eventually; is there some way to prevent this? FWIW This rarely (if ever) occurs twice in a row.</p>
  
  <p>I wrote this just now and ran it 15 times in a row without any problems, yet. It's exactly the same coding as I <em>always</em> use when using <code>JOptionPane</code>. Is there something missing?</p>
  
  <pre><code>import javax.swing.JOptionPane;
  public class SimpleJOptionPane
  {
      public static void main(String[] args)
      {
          JOptionPane.showMessageDialog(null, "Hello, World!");
      }//end main
  }//end class SimpleJOptionPane
  </code></pre>
  
  <p>Generally this problem does <em>not</em> occur. The <code>JOptionPane</code> usually displays with the intended text. What could have changed without my knowledge when it doesn't work?</p>
  
  <p>As suggested in a comment, I am looking into using EventQueue.isDispatchThread()</p>
  
  <p>The code below, as you can see, uses another method to display the JOptionPane. Is this an adequate solution?</p>
  
  <pre><code>final String ERR_TITLE = "Error";
  final String ERR_MSG = "An exception has occured; please start over.";
                      showError(ERR_MSG, ERR_TITLE);
  
  public static void showError(final String MESSAGE, final String TITLE)
  {
      JOptionPane.showMessageDialog(null, MESSAGE, TITLE, JOptionPane.ERROR_MESSAGE);
  }//end showError
  </code></pre>