See SwingUtilities.invokeAndWait(Runnable)
which:
Causes
doRun.run()
to be executed synchronously on the AWT event dispatching thread. This call blocks until all pending AWT events have been processed and (then)doRun.run()
returns. This method should be used when an application thread needs to update the GUI.