aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Setting owner of JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting owner of JDialog" Watch "Setting owner of JDialog" New topic
Author

Setting owner of JDialog

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I have a JDialog that is created at the launch of an application, and is immediately hidden in the background. Once user is moving around in the application, they can click a button that will call the show() method on the JDialog so they may view it. I want to be able to set the owner of this JDialog when the user clicks on the button. The only place I have been able to find to set this, is when the JDialog is constructed.
I need to set this when the button is pressed, because they can choose to display this dialog in a variety of different frames.
Any suggestions?
Thanks!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I don't know of a way to do this. There is no setModalParent() method or anything like that for a JDialog.
I am curious as to why you are creating the JDialog when the app launches instead of when you need it.


GenRocket - Experts at Building Test Data
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
At first, I was creating the dialog whenever the user pressed the button to bring it up. However, this was not working out too well, as this tree is being populated with data from the DB everytime it is created. And it seemed to take about 10-15 seconds for the data to all come in, which was way too long to be of any use to the user. So, I decided to add data to the tree when the app launches, then hide it. Whenever the user presses the button now, I make a call to show the dialog.
I thought about getting just the data when the app launches and putting it into some sort of collection, then the tree could be created everytime a user pressed the button, and the method to add the data from the collection to the tree could be called, but I wasn't really sure how to do this. (I figured if I could get it to work by doing what I'm doing now, I wouldn't need to worry about it).
So I guess, I'm asking a different question now....
I am currently populating the tree by looping through multiple result sets being returned. What sort of Collection can I put these result sets into to store the data until I need it?
This is currently how it is being done:

Does that sound like the right thing to do? (A penny for your thoughts!)
Thanks!
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi,
It sounds like a pretty fancy dialog. Some ideas:
1. Do you need the modality? You could write the dialog as a JFrame
that appears over component as if that component was its owner.
2. You suggested saving your db results in a collection and then building
a tree for each dialog. Why not save the results in the tree once
and build the JDialog from that each time? You could do this in a
DialogFactory which has a getInstance(owner) method.
3. It seems that you should be able to pass a JDialog owner around by
reference (though don't quote me on this, I have not tried it!).
Perhaps someone else has done this? The idea would be to set the
variable somewhere, pass it as a reference to your JDialog, and
then change it when necessary.
Good luck,
Glenn
[ April 27, 2004: Message edited by: Glenn Murray ]

Glenn Murray
Author of Yo Soy Una Vaca De Hoy
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2581

Try this -

And call this function wherever you need an owner frame for a dialog.
HTH,
- Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting owner of JDialog