Components
A component is the fundamental user interface
object in Java. Everything you see on the display in a Java application is
a component. This includes things like windows, panels, buttons,
checkboxes, scrollbars, lists, menus, and text fields. To be used, a
component usually must be placed in a container.
Container objects group components, arrange them for display using a
layout manager, and associate them with a particular display device. All
Swing components are derived from the abstract javax.swing.JComponent
class, as you saw in Figure 16-1. For
example, the JButton class is a
subclass of AbstractButton, which is
itself a subclass of the JComponent
class.
JComponent is the root of the
Swing component hierarchy, but it descends from the AWT Container class. At this
bottom level, Swing is based on AWT, so our conversation occasionally
delves into the AWT package. Container’s superclass is Component, the root of all AWT components, and
Component’s superclass is, finally,
Object. Because JComponent inherits from Container, it has the capabilities of both a
component and a container.
AWT and Swing, then, have parallel hierarchies. The root of AWT’s
hierarchy is Component, while Swing’s
components are based on JComponent.
You’ll find similar classes in both hierarchies, such as Button and JButton, List, and JList. But Swing is much more than a replacement for AWT—it contains sophisticated components as well as a real implementation of the Model-View-Controller (MVC) paradigm, ...