在JInternalFrame中显示模式对话框而不暂停应用程序 [英] Display a Modal Dialog Box in a JInternalFrame without pausing Application

查看:159
本文介绍了在JInternalFrame中显示模式对话框而不暂停应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

无论如何(无论何时有JOptionPane对话框或与此相关的任何其他对话框),对其自身的OWN内部框架进行模态化(即,框架X显示一条消息,暂停其OWN框架,但允许框架Y和其余的框架申请继续)?

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)?

推荐答案

我明白您的要求,虽然可能,但绝对不会容易.您希望模态对于弹出模态对话框的JInternalFrame是本地的".

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.

首先,您需要了解,模态弹出窗口实际上有两个部分,您可以通过自己的创作来近似它们. 1)设置模式弹出框直到弹出窗口关闭的代码; 2)当模式弹出框可见时,背景"不响应GUI事件.

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模态通过阻止当前EDT并为模态组件创建新的事件泵来实现此目的. (请参阅java.awt.Container.#startLWModal())这对您不起作用,因为您的所有JInternalFrames都共享1个EDT,这对于Swing的工作方式(单个UI线程)非常重要

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)

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

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!

这篇关于在JInternalFrame中显示模式对话框而不暂停应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆