Core Java Books

Showing posts with label JDesktopPane. Show all posts
Showing posts with label JDesktopPane. Show all posts

Thursday, 10 March 2011

JInternalFrame's Parent & Child Modality

This post is about managing JInternalFrame's within a JDesktopPane, specifically the ability to popup child JInternalFrame's from a parent JInternalFrame's. Now why would you want to do this you may ask? Well on several applications I have worked on users open forms to view/enter data, these forms then offer extra buttons to view related data in other forms. In many cases I require that the new form blocks the parent form, in short becomes modal to the parent form (not other forms).

This post offers code and a demo of a simple extension to JInternalFrame which controls the child and parent relationship. It also offers non desktop modal dialogs, but dialogs that are only modal to the parent JInternalFrame.

The functionality the provided specifically is:

  1. Frames can open child frames. The parent frame becomes busied out (lightweight modal).
  2. Clicking on a busied out parent frame brings the top related child frame to the front.
  3. Multiple parent and child hierarchy's can be on the desktop at one time.
  4. A frame can open a dialog, the dialog can be either desktop modal or modal just to the frame hierarchy it was opened from.
  5. A frame modal dialog will be brought to the front if any of its parent frames are clicked on.
Please try out the demo, the list below gives some idea of the functionality.



Play around with the demo, the menu lets you open many frames that are not related. Each frame then has buttons to let you open different children. Notice how you can click on different children and children of children and also busied out parents, you will see that the top most child frame of the associated from clicked is always brought to the front, even if iconized.

I think many people will find this functionality useful in JDesktopPane related applications

Try it out:




You can download the code from here have a look and figure it out.

Basically I have overridden JInternalFrame and added functionality to listen out for child frames opening and closing. This caused glassplanes to be installed or removed as appropriate.  Check out the logic, its easy(ish) to follow. Let me know if you can think of other uses or extensions to this.


In future I will create a post to demonstrate full modality for internal frames ;)

UPDATE: AUG 2016 - Google have retired the Google Drive Archive :( If you wish to obtain the code please email me and I can send it via email or you can obtain the whole archive here.

Please give a recommend below if you liked the article.