getting the container/jpanel of an object
i have a jbutton that is in a jpanel.. that jpanel is another jpanel and that jpanel is in a container. right now i can get the button's panel if i pressed it.. i want to know on what container the button is if i pressed it (the main root container).. how do i do this?
[277 byte] By [
hardcodera] at [2007-11-27 10:39:04]

# 2
You could always recursively call getParent like so:
private void findParents(Container c)
{
Container parentC = c.getParent();
if (parentC != null)
{
System.out.println("class: " + parentC.getClass().toString() +
", name: " + parentC.getName());
findParents(parentC);
}
}
You would call it like so:
findParents(myBtn);
Of course if you wanted to use the data programmatically, then you could output it into an arraylist rather than to the console.
Message was edited by:
petes1234