Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从不同的线程(不是 EDT)调用 JFrame 的 dispose() 方法是否安全?
不,它可能会起作用,也可能会导致问题。只需将方法包装在 SwingUtilities.invokeLater(...) 中,不用担心。
不,Swing 不是线程安全的。使用类似的东西
Runnable doWorkRunnable = new Runnable() { public void run() { myFrame.dispose(); } }; SwingUtilities.invokeLater(doWorkRunnable);