To create a graphical user interface with Swing, knowledge of the different types of Swing components and how they work is required. Swing offers a wide variety of components that can be used to easily construct many interesting GUIs. Some of the components we will be discussing are:

To make all of these different components come together as a user interface, you need to understand the concept of a containment hierarchy. A containment hierarchy describes the physical nesting of components inside of containers. In other words, it outlines where components belong in the user interface. At the top of every containment hierarchy, there is a top-level container, like a window or a dialog. Every top-level component possesses a container called the content pane. The content pane is used to contain most of the components in the user interface. Some components, like a menu bar, are added to the top-level component directly, instead of to the content pane. For more intricate user interfaces, you can use other containers, such as the JPanel class, to hold components, and then added the container to the content pane. Let us look at a sample user interface:

ContainmentHierarchy Example

Here is the containment hierarchy for the sample user interface, with the panels appropriately shaded to match:

Containment Hierarchy