title: How to dispose of SWT Shells (and Dialogs)?
body: <p>What is the proper way to dispose of SWT Shells?  I have created some Dialogs with success following the template given in the Dialog API docs.  The <a href="http://help.eclipse.org/indigo/nftopic/org.eclipse.platform.doc.isv/reference/api/index.html" rel="nofollow">SWT API for Dialog says</a>:</p>
  
  <blockquote>
    <p>The basic template for a user-defined dialog typically looks something
    like this:</p>
  
  <pre><code> public class MyDialog extends Dialog {
          Object result;
  
          public MyDialog (Shell parent, int style) {
                  super (parent, style);
          }
          public MyDialog (Shell parent) {
                  this (parent, 0); // your default style bits go here (not the Shell's style bits)
          }
          public Object open () {
                  Shell parent = getParent();
                  Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
                  shell.setText(getText());
                  // Your code goes here (widget creation, set result, etc).
                  shell.open();
                  Display display = parent.getDisplay();
                  while (!shell.isDisposed()) {
                          if (!display.readAndDispatch()) display.sleep();
                  }
                  return result;
          }
   }
  </code></pre>
  </blockquote>
  
  <p>The Dialogs I have created <em>do not</em> have their own taskbar icon on Windows, as I would expect for a Dialog.  I now want to create some Shells, which if I understand correctly <em>will</em> receive their own taskbar entry on Windows?</p>
  
  <p>In contrast to the directions given in the above API docs, I have also seen <a href="http://www.chrisnewland.com/swt-best-practice-single-display-multiple-shells-111" rel="nofollow">an article</a> which seems to suggest that having a while loop as shown in the API docs is the wrong way to do it. The article instead suggests disposing the Shell by using the close event listener.</p>
  
  <p>What is the correct way to dispose of SWT Shells (and while were on the topic, Dialogs as well)?</p>