Is it safe to call the dispose() method of a JFrame from a different thread (not the EDT)?
No. It may work or it may cause problems. Just wrap the method in a SwingUtilities.invokeLater(...) and don't worry about it.
No, Swing is not thread safe. Use something like
Runnable doWorkRunnable = new Runnable() {
public void run() { myFrame.dispose(); }
};
SwingUtilities.invokeLater(doWorkRunnable);
来源:https://stackoverflow.com/questions/1725661/is-it-safe-to-dispose-a-jframe-from-a-different-thread-in-java