• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get Frame instance from multi-layered panes  RSS feed

 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java application using multiple layers of panels. From one of the panels, I need to display a JDialog box. The constructor of the JDialog needs the parent Frame as an argument. One way I have retrieved this is by calling getParent() multiple times from within the panel, until I get an instance of the Frame. I HAVE to believe there is a more efficient way to do this?
Is there?
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Component comp = this;
while ( !( comp instanceof Frame ) )
{
comp = comp.getParent();
}
Frame frame = (Frame)comp;
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!