This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JPanel reference JFrame? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel reference JFrame?" Watch "JPanel reference JFrame?" New topic
Author

JPanel reference JFrame?

Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
Hi there everyone,

This is perhaps a dumb question, but I will ask it anyway I have a JFrame. I have a JPanel inside my JFrame. I put a Cancel button on the JPanel. I want the Cancel button to hide my JFrame, i.e. setVisible(false)

How does my Cancel button on my JPanel reference the JFrame that the JPanel is sitting in? More specifically, since it's easy for the button to get a reference to the JPanel, how does the JPanel get a reference to the JFrame so that it can make the JFrame invisible?

Thanks
Tom McAmmond
Ranch Hand

Joined: Feb 16, 2004
Posts: 58
I can now answer my own question:

SwingUtilities.getWindowAncestor(panel);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JPanel reference JFrame?
 
Similar Threads
Message dialog box displaying behind the main frame
Updating Database using JTables
Problem re-opening a JFrame
button in jpanel should change background of jframe?
Difficulties with JFileChooser