显示“JOptionPane.showMessageDialog”不停止执行流程
我目前正在开展一个项目,该项目比我最初想象的要复杂得多。我现在的目标是显示一个消息对话框,而不停止程序中主线程的执行。现在,我正在使用:
JOptionPane.showMessageDialog(null, message, "Received Message", JOptionPane.INFORMATION_MESSAGE);
但这会暂停主线程中的其他所有内容,因此它不会一次显示多个对话框,而是在另一个对话框之后显示。这 m= 可以像创建一个新的 JFrame 而不是使用 JOptionPane 一样简单吗?
I'm currently working on a project that's getting more complex than I thought it would be originally. What I'm aiming to do right now is show a message dialog without halting the execution of the main thread in the program. Right now, I'm using:
JOptionPane.showMessageDialog(null, message, "Received Message", JOptionPane.INFORMATION_MESSAGE);
But this pauses everything else in the main thread so it won't show multiple dialogs at a time, just on after the other. Could this m=be as simple as creating a new JFrame instead of using the JOptionPane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 文档:
上面的链接显示了创建对话框的一些示例。
另一种选择是在其自己的线程中启动 JOptionPane,如下所示:
这样,即使模式对话框已启动,程序的主线程也会继续运行。
According to the docs:
The link above shows some examples of creating dialog boxes.
One other option is to start the JOptionPane in its own thread something like this:
That way the main thread of your program continues even though the modal dialog is up.
您可以启动一个单独的 Runnable 来显示对话框并处理响应。
You could just start a separate
Runnable
to display the dialog and handle the response.试试这个:
try this one: