如何使主 GUI 线程'wait',直到单独的弹出窗口消失



我有一个对象,它从主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 或 modal JDialog。

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

如果你想显示多个 TopLayoutContainer,也许最好寻找 JDialog,因为有了它,你可以使用 ModalityType 和 toFront()。

方法show()不是被弃用并替换为方法 JDialog.setVisible(布尔值)吗?

最新更新