title: script running in java swing needs to wait for threads to finish
body: <p>I have a java swing application that is running scripts using javax.script. The
  scripts access the swing widgets and simulate user actions, like <code>JButton.doClick()</code>.
  Some of the widget actions cause one or more <code>Threads (SwingWorker)</code> to start, and
  I need the script to wait until all the <code>Threads</code> have completed. But the scripts run
  in the Event Dispatch Thread, so if I do, for example, a <code>CountDownLatch</code> with an
  <code>await()</code> inside a <code>FutureTask</code>, then <code>submit()</code> and <code>get()</code>, the <code>get()</code> will stop the
  EDT, and the GUI hangs. No way to have the script wait without stopping the EDT.
  Any workarounds for this problem?</p>
  
  <p>Thanks</p>