title: Java dialog does not dispose
body: <p>Java noob here.  My Swing class that extends <code>JDialog</code> does not dispose when the user presses the Windows Close button - java.exe stays in memory.  I've stripped the code right down to this shell, I still get this behaviour.</p>
  
  <p>I took a look at other samples, such as at <a href="https://stackoverflow.com/questions/7080638/basic-java-swing-how-to-exit-and-dispose-of-your-application-jframe">Basic Java Swing, how to exit and dispose of your application/JFrame</a><br>
  When I commented out the two <code>System.exit(0)</code> lines in that sample code, the class in that sample still disposed correctly.  What am I missing to make my class dispose?</p>
  
  <pre><code>import javax.swing.JFrame;
  import javax.swing.JDialog;
  public class WhyNoDispose extends JDialog{
      public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  try {
                      WhyNoDispose frame = new WhyNoDispose("my title");
                      frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                      frame.setVisible(true);
                      //System.exit(0);
                  }
                  catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
      public WhyNoDispose(String title) {
          super(new JFrame(title), ModalityType.APPLICATION_MODAL);
          pack();
      }
  }
  </code></pre>