Java Reference
In-Depth Information
Swing Container Hierarchy
The container hierarchy for any window or applet that includes Swing
components must have a Swing top-level container rather than an AWT
container. A top-level container , also called a root container is an object at
the top of the container hierarchy that displays a border and title bar. For
example, a main window should be implemented as a JFrame instance rather
than as a Frame instance if the main window will contain Swing components.
Table 7-5 displays the container hierarchy. Containers exist in both AWT and
Swing packages, but they play a more important role in Swing applications.
Table 7-5 The Swing Container Hierarchy
TYPE OF CONTAINER
PURPOSE
SWING EXAMPLE
Top-Level Containers
The components at the top of any
JApplet
Swing containment hierarchy
JDialog
JFrame
General-Purpose
Intermediate containers that can be
JPanel
Containers
used to display components
JScrollPane
JSplitPane
JToolbar
JTabbedPane
Special-Purpose
Intermediate containers that play
content pane
Containers
specific roles in the user interface,
JLayeredPane
such as layered panes or internal
JInternalPane
panes
JDesktopPane
Basic Controls
Low-level components that exist
JButton
primarily to get input from the user
JComboBox
JList
JMenu
JSlider
JSpinner
JTextField
Uneditable
Low-level components that exist
JLabel
Information Displays
solely to give the user information
JProgressBar
JToolTip
Interactive Displays of
Low-level components that display
JColorChooser
Highly Formatted
highly formatted information that
JFileChooser
Information
may be modified by the user
JTable
JText
JTree
Low-level components, also called atomic components , can stand alone in
the interface or be added to a higher level component in the hierarchy; however,
programmers should not add components directly to a top-level container, such as
a JFrame. The preferred method is to use a special-purpose container to hold com-
ponents, called a content pane . The getContentPane() method is used to create
an instance of the Container class, similar to a Panel, which does not display a bor-
der. Content panes hold individual components and are added to, and therefore
contained by, the JFrame. Programs that use a content pane extend JFrame and use
add() methods to add components to the instance of the content pane.
 
Search WWH ::




Custom Search