How can I create a modal JDialog, that blocks only the owner (JFrame or JDialog) and not the whole application (or applet)?

Sandip Chitale

You could use a non-modal dialog - Steps are -

  1. Add a WindowListener to the JDialog. In the windowClosed(WindowEvent we) "enable" the JFrame.
  2. Before showing the JDialog disable the JFrame.
  3. Show the JDialog.
While the JDialog is showing user will not be able to interact with the JFrame. Once the Jdialog is closed the windowClosed(WidnowEvent we) will be called which will reenable the JFrame (as above).

Yes, I have been also annoyed by the flip-flops in the behaviour of modal dialogs. In fact making it Application modal is almost a death nail for SDI applications. Sun is going to support degree of modality in future version (JDK1.4 I think).

Davanum Srinivas adds

You can extend the Semi-Modal concept as described in JavaTip-89 at:

http://www.javaworld.com/javaworld/javatips/jw-javatip89.html

This involves manipulating event queues to handle the Keyboard and Mouse events.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact