What is going on behind the scenes when I add a Component (like a button) to a Container (like a Frame)?

Scott Stanchfield

First, if the component is already inside another component, it is removed from that component.

Next, a pointer to the component is added to the container's "components" list. This keeps track of which components are contained within a parent container.

Adding the component also invalidates the container. When the container needs to be repainted, it lays out the components (possibly using a layout manager)