Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with getParent() with little code example

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
Hello I am trying to call a method in nested panel which is two panels down(intuitevely speaking). Anyway this method will not get called method. I cast the container to the correct type of course, but should getParent() not pass a reference?

This is what I've done

System.out.println("Hope this works");
(((TheRightObject)(getParent().getParent()).aMethodInTheRightObject();
System.out.println("Did it work?");
System.out.println("33333333333333");

How comes the only thing that runs is Hope this works.
and nothing else runs Did it work? does not get printed nor do the 3's. And most importantly aMethodInTheRightObject() does not run.

Please could someone help

thanks in advance

Chris

PS I've tried all sorts such as putting the second call of getParent() in the panel one up, but this has not made a different. It is seeming like you cannot get the parent of a perent and call methods on it.
 
Hi Chris,

I don't think you need the cast. Just
Code:
getParent().getParent().aMethodInTheRightObject();
should do what you want. Assuming that aMethodInTheRightObject() is indeed a method in the panel two levels Up.
 
Please ignore this message the getParent() thing works fine!, but you do need the cast I think otherwise you get just a container object.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top