File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel reference JFrame?

 
Tom McAmmond
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can now answer my own question:

SwingUtilities.getWindowAncestor(panel);
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic