疑难解答:JDialog 是模态的,但不是模态的?

发布于 2024-07-15 07:26:26 字数 603 浏览 10 评论 0原文

对此感到困惑,但也许,只是也许,有人以前遇到过这个问题,可以为我指明正确的方向。

我有一个 JDialog 用于显示长时间运行的任务的进度,我已将其明确创建为具有定义的所有者的模式:

  progressDialog = new JDialog( ((Dialog)windowParent), true );
  ...
  progressDialog.setVisible( true );

稍后,一旦任务完成,我会再次关闭对话框:

protected void done() {
  SwingUtilities.invokeLater( new Runnable() {
     public void run() {
        progressDialog.setVisible( false );
     }
  } );
}

在非常罕见的情况下,对话框) 不会关闭,并且 b) 不是真正的模式,即用户能够与(理论)对话框后面的窗口进行交互。 有什么想法可能导致这种情况吗? 不幸的是,这种情况很少发生,而且到目前为止,仅在 Linux 系统上发生。 这可能是 Swing 错误还是我可能做错了什么?

Stumped by this, but maybe, just maybe, someone has had this problem before and can point me in the right direction.

I have a JDialog for displaying the progress of a long-running task, which I have expressly created as modal with a defined owner:

  progressDialog = new JDialog( ((Dialog)windowParent), true );
  ...
  progressDialog.setVisible( true );

Later on, once the task is complete, I close the dialog again:

protected void done() {
  SwingUtilities.invokeLater( new Runnable() {
     public void run() {
        progressDialog.setVisible( false );
     }
  } );
}

Under very rare circumstances, the dialog a) does not close, and b) is not truly modal, i.e. the user is able to interact with the window behind the (theoretical) dialog. Any ideas what might be causing this? Unfortunately it happens very rarely and until now, only on Linux systems. Could this be a Swing bug or am I possibly doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-07-22 07:26:26

尽管我无法为您的问题提供明确的解决方案,但我可以告诉您,我在 Linux 上看到了模式对话框的各种奇怪行为 - 其中许多取决于适当的窗口管理器。

对于我们的销售点系统,我们最终使用了非常简约的“flwm”窗口管理器,因为它提供了最可靠和最理想的属性。 但不推荐将其用于现代 Linux 桌面。

至于模态本身:如果您可以使用 Java 6,您可能想了解一下 JDK6 模态的更改和增强:Sun 博客 以及随附的 Javadoc

Even though I cannot provide a definitive solution to your problem, I can tell you that I have seen all sorts of strange behavior with modal dialogs on Linux - many of them depending on the Window manager in place.

For our point of sale system we ended up using the very minimalistic "flwm" window manager, because it provided the most reliable and desired properties. Would not recommend it for a modern Linux desktop however.

As for modality itself: If you can use Java 6 you might want to have a look into the JDK6 modality changes and enhancements: Sun Blog and the accompanying Javadoc for the Dialog.ModalExclusionType

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文