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

sky*_*ork 1 java user-interface swing multithreading awt

我有一个从主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
...
...
Run Code Online (Sandbox Code Playgroud)

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

Hov*_*els 7

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


mKo*_*bel 5

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

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

是不是show()弃用了方法并用方法JDialog.setVisible(boolean)替换?

  • +1但请注意你的语法和拼写. (3认同)