title: How to force ImageJ to close all its windows without close event error?
body: <p>I am writing a Java application for image analysis which at one point opens <code>ImageJ</code> with</p>
  
  <pre><code>ImageJ ij = new ImageJ();
  </code></pre>
  
  <p>and also opens a Windows containing an <code>ImagePlus</code>. </p>
  
  <p>Now, whenever one closes <code>ImageJ</code> first, the <code>ImagePlus</code> will <strong>not close</strong> when pushing the close button. The other way around works, however in both cases an exception is thrown after closing <code>ImageJ</code>:</p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
      at java.awt.EventQueue.invokeAndWait(EventQueue.java:1288)
      at java.awt.Window.doDispose(Window.java:1209)
      at java.awt.Window.dispose(Window.java:1147)
      at ij.ImageJ.run(ImageJ.java:784)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: null source
      at java.util.EventObject.&lt;init&gt;(EventObject.java:56)
      at java.awt.AWTEvent.&lt;init&gt;(AWTEvent.java:337)
      at java.awt.event.InvocationEvent.&lt;init&gt;(InvocationEvent.java:285)
      at java.awt.event.InvocationEvent.&lt;init&gt;(InvocationEvent.java:174)
      at sun.awt.X11.XBaseMenuWindow.dispose(XBaseMenuWindow.java:907)
      ...
  </code></pre>
  
  <p>I don't know whether it is related as it happens in both cases. </p>
  
  <p>Any suggestions on how to force <code>ImageJ</code> to close all its windows?</p>