在 JFrame 上显示 JDialog(“请稍候”)
我有一个 JFrame
,这个 JFrame
有一个 JButton
。
我想在 JButton
中首先显示 JDialog
(显示“请稍候”
)并执行其他代码然后关闭JDialog
。
但是当显示JDialog
停止时执行其他代码JButton
。
I have a JFrame
and this JFrame
has a JButton
.
I want in JButton
first show JDialog
(display "Please wait"
) and execute other code then closing JDialog
.
But when showing JDialog
stopped to execute other code on JButton
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
Thread
上启动其他处理(例如在SwingWorker
) 并在其开头调用modalDialog.setVisible(true)
。在任务结束时调用setVisible(false)
。Start the other processing on a
Thread
(e.g. in aSwingWorker
) and at the start of it, callmodalDialog.setVisible(true)
. At the end of the task callsetVisible(false)
.我建议创建一个简单的 JDialog,然后在代码运行后将其处置。您可以使用以下代码创建 JDialog:
并像这样实现它:
I would suggest creating a simple JDialog and then disposing it after your code has run. You can create your JDialog with the following code:
And implement it like this:
也许 jdialog 处于模态模式,请尝试更改 jdialog 的模态属性:
yordialog.setModal(false)
。Maybe the jdialog is in modal mode, try change the modal property of the jdialog :
yordialog.setModal(false)
.它停止了,因为您正在使用“主线程”,它用于执行代码并显示 JDialog。
要解决这个问题,您应该研究类似 SwingWorker 的内容
It stopped because you are using the "MAIN-Thread" which is used to execute the code and show the JDialog.
To solve this you should look into something like SwingWorker