The JModalWindow project was created to support modal functionality, similar to JDialog, without blocking all frames. Source code, binaries, API documentation, and a demo are all available for download.
To run with minimal configuration type: java -jar swingx_v0203_demo.jar -minimal (no blurring of blocked window, no busy cursor when moving the mouse cursor over the blocked window and disabled iconify of a blocked internal frame.)
To run article sample type: java -jar swingx_v0105_sample.jar
Alternatives
If you just need a window-specific modal frame
Santhosh Kumar's Weblog
might provide a less intrusive alternative.
Or take a look at the New
Modality API
in Mustang.
Note: if the class files are packaged in a jar make sure the images are also packaged in that jar.
The image cursor.gif is available in the directory /usr/images.
Create a zip or jar file …/dist/lib/usr.zip containing the image and including the subfolders
/usr/images. Then add the following line to your code:
Note: In UIManager.put("swingx.busy.cursor", "/home/images/custom-cursor"); remove the first slash,
because there is a difference between
getInstance().getClass().getClassLoader().getResource(…); which I used and
getInstance().getClass().getResource(…);
in the way they retrieve the resource.
By the way: Due to a Win32 problem the cursor to must be 32 x 32. To create a 16 x 16 icon use for example the upper left
16 x 16 pixels and fill the rest with a transparent color.
I'm having a problem using the waitForClose() method.
Basically, when I use this method, the entire application freezes and won't respond to events or repaint itself.
Answer
This is due to the fact that wait() shouldn't be called on the event dispatch thread
(see How to Use Threads).
Which means the waitForClose() is useless in ActionListeners and the like.
For this reason waitForClose() now throws the following
Error("Cannot call wait from the event dispatcher thread")2)
when the method is called on the event dispath thread.
If you need to implement some action, when the window is closed, use the windowClosed method of for example the
WindowAdapter and supply this to the
addWindowListener
method of the window, you want to monitor. For an example of its usage see: TestModalFrame method init()jbNormalWindow.addActionListener(…);
2) Since enhancement 19
it is now also possible to simulate wait on the event dispatch thread (EDT). Just call the enableWaitOnEDT()
method of the JModalConfiguration class to activate this. Note: Because this method could throw a
java.lang.SecurityException if a security manager exists and its
SecurityManager.checkAwtEventQueueAccess() method denies access to the EventQueue, it
isn't activated by default.