We help IT Professionals succeed at work.

JDialog childs and minimizing the JFrame "father"

mandriluy
mandriluy asked
on
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 ?
Comment
Watch Question

Awarded 2011
Awarded 2011
Commented:

In the API
http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Dialog.html

we read:

A dialog must have either a frame or another dialog defined as its owner when it's constructed. When the owner window of a visible dialog is minimized, the dialog will automatically be hidden from the user. When the owner window is subsequently restored, the dialog is made visible to the user again.

So it looks like it should be hidden

Did you mention  this Jframe in the constructor of JDialog ?

Author

Commented:
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.
Awarded 2011
Awarded 2011

Commented:

> 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



Author

Commented:
A Singleton with a parameter is an anti-pattern, but seems the only option here.
Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
	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

Awarded 2011
Awarded 2011

Commented:
what is not working ?

Author

Commented:
I minimize the parent JFrame and the JDialog doesn't minimize.
Awarded 2011
Awarded 2011

Commented:

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?

Author

Commented:
None of my dialogs are Modal, im using JDK 6
Awarded 2011
Awarded 2011

Commented:
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

Author

Commented:
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.
Awarded 2011
Awarded 2011

Commented:
Really strange ..

Author

Commented:
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 .

Author

Commented:
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