title: True application modal SWT shell from AWT JFrame
body: <p>I have a Java Swing application and I'm embedding an SWT widget to it. I'm trying to display an SWT <code>Shell</code> from my AWT <code>JFrame</code> but cannot make it application modal. The <code>JFrame</code> can still be focused and button clicks will register to the EDT. What steps do I take to make the <code>Shell</code> behave like a modal AWT dialog?</p>
  
  <p>I have read <a href="http://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html" rel="nofollow noreferrer">this outdated tutorial</a> but it only explains how to do it if the application is running on the SWT event thread. I also tried to hack this with a modal <code>JDialog</code> but the behavior is ugly at best. Remove the comments from the minimum working example to demo it. <code>SWT.ON_TOP</code> is troublesome in itself, since ithe <code>shell</code> will stay on top of every window.</p>
  
  <p><a href="https://stackoverflow.com/questions/6763254/showing-swt-modal-dialog-from-awt-swing">This question</a> did not help.</p>
  
  <p>SSCE</p>
  
  <pre><code>public class ModalDialogExample extends JFrame {
  
  public ModalDialogExample()
  {
      this.setSize(500, 500);
      this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
  
  public static void main(String[] args)
  {
      JFrame frame = new ModalDialogExample();
      JButton button = new JButton("CLick me");
      button.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
  //              JDialog modalDialog = new JDialog();
  //              modalDialog.setSize(new Dimension(0,0));
  //              modalDialog.setModalityType(ModalityType.APPLICATION_MODAL);
              Display display = new Display();
              Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.OK | SWT.ON_TOP | SWT.APPLICATION_MODAL);
              shell.setSize(200,200);
              shell.open();
              shell.forceActive();
  //              modalDialog.setVisible(true);
              while (!shell.isDisposed()) {
                  if (!display.readAndDispatch())
                      display.sleep();
              }
              display.dispose();
          }
      });
      frame.getContentPane().add(button);
      frame.setVisible(true);
  }
  }
  </code></pre>