在 JInternalFrame 中显示模态对话框而不暂停应用程序

发布于 2024-08-04 11:29:28 字数 245 浏览 2 评论 0原文

我有一个使用 JInternalFrames 的 MDI 应用程序。每个内部框架执行不同的操作,但是,其他一些框架使用 JOptionPane 显示消息,这当然会暂停整个应用程序。

无论如何(每当 JOptionPane 对话框或任何其他对话框时)是否可以对其自己的内部框架进行模式化(即框架 X 显示一条消息,暂停其自己的框架,但允许框架 Y 和应用程序的其余部分继续)?

是否可以在不更改代码(或至少只更改其中一小部分)的情况下做到这一点?

I have an MDI application which uses JInternalFrames. Each internal frame does a different operation, however, some of the other frames display messages using JOptionPane, which of course, pauses the entire application.

Is there anyway to (whenever a JOptionPane dialog or any other dialog box for that matter) be modal to its OWN internal frame (i.e. frame X displays a message, pauses its OWN frame, but allows frame Y and the rest of the application to continue)?

And is it possible to do this without having to change the code (or at least only a little of it)?

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

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

发布评论

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

评论(2

苍白女子 2024-08-11 11:29:29

我明白你在问什么,这可能是可能的,但绝对不会容易。您希望模态对于弹出模态对话框的 JInternalFrame 来说是“本地”的。

首先,您需要了解模态弹出窗口实际上有两个部分,可以通过您自己创建的内容来近似。 1) 设置模态弹出窗口的代码会阻塞,直到弹出窗口关闭,并且 2) 当模态弹出窗口可见时,“背景”不会响应 GUI 事件。

True modality 通过阻止当前的 EDT 并为模态组件创建新的事件泵来实现此目的。 (请参阅 java.awt.Container.#startLWModal())这对您不起作用,因为您的所有 JInternalFrames 共享 1 EDT,这对于 Swing 的工作方式非常基础(单 UI 线程)

但是,您的 JInternalFrames 是JRootPanes,这意味着它们有玻璃板。您可以使用它来创建您自己的各种形式。这个想法是让每个 JInternalFrame 的模式弹出窗口显示在安装在 JInternalFrame 上的透明玻璃板上的中心。添加一个将鼠标事件消耗到透明玻璃板的鼠标侦听器,这将为您提供模态功能#2(背景似乎无响应)。使用 OO 而不是阻塞来获取功能#1(让您的模态弹出窗口采用 IModalPopupListener(我做了这个 - 您必须创建它)对象以在模态弹出窗口消失时进行回调)。

我希望这是有道理的!祝你好运!

I see what you're asking, it might be possible but it definitely won't be easy. You want the modality to be "local" to the JInternalFrame that popped up the modal dialog.

First you need to understand that there are really 2 parts to a modal pop-up that can be approximated by something of your own creation. 1) The code that sets the modal pop-up blocks until the pop-up closes, and 2) The "background" does not respond to GUI events while the modal pop-up is visible.

True modality achieves this by blocking the current EDT and creating a new event pump for the modal component. (See java.awt.Container.#startLWModal()) This isn't going to work for you, because all of your JInternalFrames share 1 EDT, which is pretty fundamental to how Swing works (single UI thread)

However, your JInternalFrames are JRootPanes, which means that they have glasspanes. You can use this to create your own modality, of sorts. The idea is to have your modal pop-up for each JInternalFrame appear centered on a transparent glasspane that gets installed on the JInternalFrame. Add a mouse listener that consumes mouse events to the transparent glasspane, this will get you modality feature #2 (background seems non-responsive). Use OO instead of blocking to get feature #1 (Have your modal popup take an IModalPopupListener (I made this up -you'll have to create it) object to call back when the modal pop-up dissapears).

I hope this make sense! Good luck!

毁梦 2024-08-11 11:29:29

这看起来很有希望:

创建模态内部框架

编辑

您的评论(来自链接页面):

但是有时您可能会
想要一个内部框架中的对话框
是模态的。本技术提示将向您展示
如何在中创建模式对话框
内部框架。

这不正是您所寻找的吗?

This looks promising:

Creating Modal Internal Frames

Edit

Responding to your comment (from linked page):

There are times however when you might
want a dialog in an internal frame to
be modal. This Tech Tip will show you
how to create a modal dialog in an
internal frame.

Isn't it exactly what your looking for?

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