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 ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> 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
ASKER
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
but passing frame to dialog - seems the main sense of dialog in it
ASKER
public static MainDentistDlg getInstance(MainWindowFrm father) {
if(instance == null)
instance = new MainDentistDlg(father);
return instance;
}
private MainDentistDlg(MainWindowFrm father) {
//irrelevant code
}
It's not working... im passing the MainWindowFrm object.
MainDentistDlg dialog = MainDentistDlg.getInstance(instance);
dialog.setVisible(true);
what is not working ?
ASKER
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?
ASKER
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
and if it does not work - you can always inplement wondows listener and minimize in th even hanfdler
ASKER
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 ..
ASKER
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 .
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 .
ASKER
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);
}
ASKER
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.