For Swing components, it all starts with a JFrame set (you can also have JWindow and JDialog, but usually you have at least one root frame). Most likely, all you care about is the contentPane of this JFrame (but you could also take care of its owners, etc.).
So, from JFrame you can get the content panel as follows:
Container contentPane = frame.getContentPane();
From there, you can begin to descend the component tree using:
Component[] children = contentPane.getComponents();
From a child, you can get a parent with:
Container parent = child.getParent();
To add a component to a container:
container.add(someComponent); container.validate();
To remove a component from the container:
container.remove(someComponent); container.validate();
To move a component from one container to another, simply remove it from one and add it to another.
I am not sure if this answers your question. It would be easier if you could post real-life examples of what you are trying to do.
source share