by interfaces. For example, the model for a button is defined by the ButtonModel interface.
UI delegates are classes that inherit ComponentUI. For example, the UI delegate for a button
is ButtonUI. Normally, your programs will not interact directly with the UI delegate.
Components and Containers
A Swing GUI consists of two key items: components and containers. However, this distinction
is mostly conceptual because all containers are also components. The difference between the
two is found in their intended purpose: As the term is commonly used, a component is an
independent visual control, such as a push button or slider. A container holds a group of
components. Thus, a container is a special type of component that is designed to hold other
components. Furthermore, in order for a component to be displayed, it must be held within
a container. Thus, all Swing GUIs will have at least one container. Because containers are
components, a container can also hold other containers. This enables Swing to define what
is called a containment hierarchy, at the top of which must be a top-level container.
Let's look a bit more closely at components and containers.
In general, Swing components are derived from the JComponent class. (The only exceptions
to this are the four top-level containers, described in the next section.) JComponent provides
the functionality that is common to all components. For example, JComponent supports the
pluggable look and feel. JComponent inherits the AWT classes Container and Component.
Thus, a Swing component is built on and compatible with an AWT component.
All of Swing's components are represented by classes defined within the package
javax.swing. The following table shows the class names for Swing components (including
those used as containers).
Search WWH :