title: Rendering Problem with Swing App and Modal Dialogs
body: <p>I have a Java/Swing desktop application (Java 6u16 on Windows XP) which occasionally appears to the users to hang. I say appears to because in reality what is happening is that the application is showing a modal dialog but this dialog is not being rendered. If the user uses Alt-Tab to switch away from the application and then subsequently returns to it, the dialog gets rendered correctly. Additionally, if a remote user connects to the session via NetOp (a VNC/Remote Desktop workalike) this also causes the GUI to be redrawn correctly. </p>
  
  <p>The app runs via JavaWebstart. Since I've heard of rendering issues being caused by DirectDraw, I added the following to the JNLP </p>
  
  <pre><code>&lt;property name="sun.java2d.noddraw" value="true"/&gt;
  </code></pre>
  
  <p>but the problem still occurs (If I have understood correctly, this will switch off DirectDraw and Direct3d completely: see <a href="http://download.oracle.com/javase/1.5.0/docs/guide/2d/flags.html#noddraw" rel="nofollow noreferrer">http://download.oracle.com/javase/1.5.0/docs/guide/2d/flags.html#noddraw</a>)</p>
  
  <p>I'm out of ideas on this one, any suggestions would be greatly appreciated.</p>
  
  <p>Thanks,<br>
  Phil</p>
  
  <p><em><strong>Edit...</strong></em></p>
  
  <p>I have an abstract dialog class which extends JDialog and which all other dialogs extend. It contains the following method:</p>
  
  <pre><code>public void showDialog() {      
      initKeyBindings();
      Application.getApplication().deactivateScannerListener();
      setVisible(true);
  }
  </code></pre>
  
  <p>Whenever I want to display a dialog, I call showDialog(). The initKeyBindings method sets up an ActionMap while the second line is application specific (Application is a singleton, I'm disabling the JPOS scanner listener while the dialog is displaying).</p>
  
  <p>There is a corresponding hideDialog() method as follows:</p>
  
  <pre><code>public void hideDialog() {      
      setVisible(false);
      Application.getApplication().activateScannerListener();
      dispose();
  }
  </code></pre>
  
  <p>Thanks,
  Phil</p>
  
  <p><em><strong>Edit...</strong></em>
  Sorry about this, one more edit: all of the dialogs have a parent. The AbstractDialog class will default to the main application frame if no other parent is specified.</p>
  
  <p>FYI
  For anyone following this, I've added the following to my code:</p>
  
  <pre><code>if (SwingUtilities.isEventDispatchThread()) {
          initialiseAndShowDialog();
  } else {
      SwingUtilities.invokeAndWait(new Runnable() {
              @Override
              public void run() {
                 initialiseAndShowDialog();
              }
      });
  }
  </code></pre>
  
  <p>This ensures that the dialog is only opened from the EDT.</p>