954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Linking Multiple JFrames

I have four JFrames open in an application. I wish for one of them to be the base JFrame, and when one of the others is closed than everything except the base frame will dispose.

How do I link the other three JFrames so that when any one of them is closed (disposed) they all close?

LondonJava
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Keep a List of the dependent frames in your base frame. When closing one of the dependents, call a method on the base to dispose of all dependents.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

1) not possible, without huge code for AWT workaround

2) you are talking about JFrame#setDefaultCloseOperations(JFrame.EXIT_ON_CLOSE) with 3 JDialogs##setDefaultCloseOperations(JDilaog.DISPOSE_ON_CLOSE)

3) don't do it that this way its so hard job manage anything betweens four hight level container, you have to put there some hierarchy, result is JFrame as parent with three JDialogs which have got a parent

4) very carrefully with top-level containers , don't create lots of these Object, because they are still in the memory untill current JVM instance exists , you can only to remove its contents and dispose Graphics/Graphics2D

5) look at WindowListener , then you can create own class that manageing lifecycle for all of four Top-Level Containers separatelly or altogether, up to you,

mKorbel
Veteran Poster
1,141 posts since Feb 2011
Reputation Points: 480
Solved Threads: 224
 

What I would do is...
One JFrame (your base frame) and 3 JDialogs.
I think that this would be easier to implement than 4 JFrames.

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: