[英]Why JDialog doesn't close after JOptionPane showMessageDialog?
When my server app is starting, a JDialog
opens to indicate to the user that the app is loading. 当我的服务器应用程序启动时,将打开一个JDialog
来向用户指示该应用程序正在加载。 But between the opening of JDialog
and its closing, I use JOptionPane.showMessageDialog()
to display another message. 但是在JDialog
打开和关闭之间,我使用JOptionPane.showMessageDialog()
显示另一条消息。
The problem is, if I display this new message before closing JDialog
then JDialog
will never close even if I close JOptionPane
dialog. 问题是,如果我在关闭JDialog
之前显示此新消息,那么即使我关闭JOptionPane
对话框, JDialog
也永远不会关闭。 If I remove the JOptionPane
dialog then the JDialog
closes as usual. 如果删除JOptionPane
对话框,则JDialog
将照常关闭。
Why opening JOptionPane.showMessageDialog()
disable JDialog
closing ? 为什么打开JOptionPane.showMessageDialog()
禁用JDialog
关闭?
Is use this code to open JDialog
: 正在使用此代码打开JDialog
:
final JDialog dlg = new JDialog(this, "Veuillez patienter, le serveur démarre...", true);
dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dlg.setSize(300, 75);
dlg.setResizable(false);
dlg.setLocationRelativeTo(this);
Thread t = new Thread(() -> {
dlg.setVisible(true);
});
t.start();
And this code to close it: 并用以下代码关闭它:
dlg.setVisible(false);
And between these lines of code I do this to open message dialog: 在这些代码行之间,我执行此操作以打开消息对话框:
JOptionPane.showMessageDialog(this, String.format(I18n.i18n.getString("PopupWifiCreated"), this.SSID, this.password), null, JOptionPane.INFORMATION_MESSAGE);
Anyone has an idea? 有人有主意吗?
Thanks. 谢谢。
In my opinion setting the visibility of any frame to false is not the greatest idea. 我认为将任何框架的可见性设置为false都不是个好主意。 Of course it depends what are your goals, but I'd still not recommend it. 当然,这取决于您的目标,但是我仍然不建议这样做。 It should be done like eg: 应该像这样完成:
dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dlg.close();
or
dlg.dispose();
If it still wont work, try to reverse the order of dialogs - first show messageDialog, and then JDialog. 如果仍然无法执行,请尝试反转对话框的顺序-首先显示messageDialog,然后是JDialog。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.