How to get Frame of your app?

I want to create a JDialog, and I'd like to construct

it with a Frame object passed in so it floats on top

of my app instead of somewhere else.

How the heck to I get a reference to my main JFrame ?

I have a JFrame, then a JPanel, then some buttons.

One of the buttons will call the JDialog but I have

no idea how to get a hold of it.

Please help.

There must be a simple statement I can use to get the

main JFrame.

Thanks

Josh

[506 byte] By [jgunder] at [2007-9-27 1:02:04]
# 1
dialog.getOwner() will give you the parent of your dialogJFrame f = (JFrame)dialog.getOwner();will work if you have created the dialog with JFrame as parent.
bipinr at 2007-7-4 18:21:27 > top of Java-index,Archived Forums,Swing...
# 2

I haven't created the dialog yet.

I need a reference to my JFrame before

I can do that. Frame object is part

of the JDialog constructor.

First I need to get the frame object

Then I can create the dialog.

How can I get a reference to my JFrame.

Still need help.

jgunder at 2007-7-4 18:21:27 > top of Java-index,Archived Forums,Swing...
# 3

Ok.

I think you have a JFrame and

a JPanel added to JFrame,

And this JPanel contains JButton, Am I right?

Then

Container parent = button.getParent(); //this will be theJPanel

Container grandParent = parent.getParent(); //this will be your JFrame

BR

bipinr at 2007-7-4 18:21:27 > top of Java-index,Archived Forums,Swing...
# 4
Awesome, thanks!
jgunder at 2007-7-4 18:21:27 > top of Java-index,Archived Forums,Swing...