如何使主GUI线程“等待”,直到单独的弹出窗口消失

我有一个从主GUI线程调用的对象,并显示一个单独的JFrame几秒钟然后消失(使用一个计时器)。 现在我想让主GUI线程等到弹出的JFrame窗口消失。 例如,在主GUI代码上:

// initiate the object and show the pop-up JFrame DisappearingJFrame djf = new DisappearingJFrame (); djf.show (); // now the main GUI thread should wait // and after the pop-up JFrame disappears, the rest of the code is then executed ... ... 

任何建议都会受到欢迎。 谢谢。

不要使用单独的JFrame来为此构建模式对话框。 使用JOptionPane或模态JDialog。

我有一个从主GUI线程调用的对象,并显示一个单独的JFrame

如果你想展示多个TopLayoutContainer或许最好寻找JDialog,因为你可以使用ModalityType和toFront() 。

方法show()已弃用并替换为方法JDialog.setVisible(boolean) ?