tags:

views:

459

answers:

2

Hi,

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

A: 

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?

Andreas_D
Any idea how to make for 1 frame only??
Kryten
Well I tried the example they give with 2 internal frames instead of 1 and they were both modal (i.e. I couldn't access frame 2). The parent frame however was non-modal. All I want to do is have frame 1 modal, but frame 2 and the parent frame non-modal.
Kryten
From the reading, it look like a perfect match to your problem, I must admit, that I never tried it. Hope you find a working solution :)
Andreas_D
A: 

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!

CarlG
You're right, that is exactly what I want. Thanks! :)
Kryten