如何让主 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
...
...
欢迎任何建议。谢谢。
I have an object which is invoked from the main GUI thread and shows a separate JFrame for a number of seconds and then disappear (with the use of a timer). Now I want to make the main GUI thread to wait until the pop-up JFrame window disappears. For example, on the main GUI code:
// 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
...
...
Any suggestion would be welcome. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用单独的 JFrame,因为这是模式对话框的构建目的。使用 JOptionPane 或模态 JDialog。
Don't use a separate JFrame for this is what modal dialogs were built for. Use either a JOptionPane or a modal JDialog.
如果您想显示多个 TopLayoutContainer(s) 也许最好寻找 JDialog 因为有了它,您可以使用 ModalityType & toFront() 。
方法
show()
是否已弃用并替换为方法 JDialog.setVisible(boolean)?If you want to show more than one TopLayoutContainer(s) maybe it is better to look for JDialog because with that you can play with ModalityType & toFront().
Isn't method
show()
deprecated and replaced with method JDialog.setVisible(boolean)?