It is convenient to be able to aggregate these sets of components so that they can be treated as one object. For example they can all be assigned the same font or foreground color. Additionally, grouping related components together makes it easier to arrange them on the screen. Instead of assigning positions to each of our three buttons, we can group them together and place the button container where we want it. Containment hides detail and simplifies GUI layout.
Containers can also store other containers.
This allows the developer to construct small portions of the GUI, then aggregate them into a container unit, and then manipulate these higher level units without worrying about the individual components. Thus containment is an abstraction technique that helps to hide complexity and simplify GUI layout. A Swing GUI typically has a tree-like structure, with components as the leaves and containers as the internal and root nodes. This tree structure is referred to as the containment hierarchy. One more critical part of GUI design is handling user initiated events .