Link to home
Start Free TrialLog in
Avatar of abhishekroy
abhishekroy

asked on

How to get JInternalFrame form its contentPane??

Hi,
   I have a JInternalFrame in my application and am adding a toolbar and JPanel to its contentPane.
   I want to get to the JInternalFrame from the JPanel added to the contentPane. I am using getParent() and am able to get to the contentPane successfully but I'm not able to get to the JInternalFrame.
   Any help would be appreciated.Thanks in advance.
Abhishek.
Avatar of schybert
schybert

You could use:
panel.getParent().getParent().getParent().getParent()

but there has to be a better way :-)
Avatar of abhishekroy

ASKER

Nopes! Doesn't work.
ASKER CERTIFIED SOLUTION
Avatar of Ovi
Ovi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tip: the same algorithm is used for detection of top most Frame when you'll create a modal Dialog or JDialog.
Thanks that works!
you're welcome
Hey!
The above code works but not for my case.
I have a class WANView which extends JInternalFrame.

I am using the following code for accessing the JInternalFrame

Container parent = WANPanel.this;

/* WANPanel extends JPanel
 * An instance of WANPanel is added to the WANView Frame's
 * contentPane.
 */

while(!(parent instanceof WANView) && parent != null)
parent = parent.getParent();
WANView parentFrame = (WANView) parent;
parentFrame.toggleEditMode(false);

It's not working and throws exceptions.
What's the mistake I am making?
Please help.