Link to home
Start Free TrialLog in
Avatar of mandriluy
mandriluy

asked on

JDialog childs and minimizing the JFrame "father"

Anal criminals,

I have a JFrame with a Menu and items that creates new JDialog's (singleton) and those JDialog have the setAlwaysOnTop(true).. but when i minimize the JFrame "father" the JDialog's stay there floating and don't minimize with the JFrame, is there a way i can minimize everything and then restore ?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mandriluy
mandriluy

ASKER

I was not passing the JFrame for this JDialog, mainly because i was using Singleton here, i modified my singleton but im not sold on this one.

Do you think calling the jdialog getInstance(jframe);  is the right thing to do ? im using this jdialog from another jdialog's so this wont work unless i call getInstance(null);  wich i don't really like at all. Or i can  overload getInstance() and constructor .... seems like its not working.

> jdialog getInstance(jframe);  is the right thing to

Singleton or not does npt matter - you should pass it to private constructor, so that frame is represented in the dialog - then dialog will be depdnednt
on frame

You need to pass through your original frame through the tiesr to all your jsialog - then they will be depdnewdnt on your frame



A Singleton with a parameter is an anti-pattern, but seems the only option here.
alternatively you can catch even of closing frame and in the event handler close your dilaog(s)
but passing frame to dialog - seems the main sense of dialog in it
	public static MainDentistDlg getInstance(MainWindowFrm father) {
		if(instance == null)
			instance = new MainDentistDlg(father);
		return instance;
	}
	
	
	private MainDentistDlg(MainWindowFrm father) {
           //irrelevant code
        }

Open in new window


It's not working... im passing the MainWindowFrm object.

MainDentistDlg dialog = MainDentistDlg.getInstance(instance);
dialog.setVisible(true);

Open in new window

what is not working ?
I minimize the parent JFrame and the JDialog doesn't minimize.

DOn't know it is written again here, that dialog should minimize together with the owner:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/modality/


And i'm sure that was the case in my applications.
Don't think  that this private constructor can change that

Read below in that document about modlity - try to chenge modality - wuill it affect the minimizing behavior?

which version of Java are you using?
None of my dialogs are Modal, im using JDK 6
don't know - try normal way without singletons - at lest for the test

and if it does not work - you can always inplement wondows listener and minimize in th even hanfdler
I tried without singleton and doesn't work either... weird thing!! maybe its some property blocking this functionality i will try with simpler windows examples.
Really strange ..
I made a new project with this:

JFrame Window
JDialog Child

The window has only a button that creates a new Child instance and passes the Window object to the Child constructor then setVisibility(true) . When pressing the button.. the Jdialog appears, when minimizing the JFrame Window, the JDialog remains visible and does not minimize :O .
LOL... failsauce! , i forgot to call the JDialog parent class constructor inside my jdialog constructor and pass the object ¬¬

	
private MainDentistDlg(MainWindowFrm father) {
           //not so irrelevant code :P
           super(father);
}

Open in new window