Java Reference
In-Depth Information
tained within another container. Thus, you can use lightweight containers to create sub-
groups of related controls that are contained within an outer container.
The Top-Level Container Panes
Each top-level container defines a set of panes . At the top of the hierarchy is an instance of
JRootPane . JRootPane is a lightweight container whose purpose is to manage the other
panes. It also helps manage the optional menu bar. The panes that compose the root pane
are called the glass pane , the content pane , and the layered pane .
The glass pane is the top-level pane. It sits above and completely covers all other panes.
The glass pane enables you to manage mouse events that affect the entire container (rather
than an individual control) or to paint over any other component, for example. In most
cases, you won't need to use the glass pane directly. The layered pane allows components
to be given a depth value. This value determines which component overlays another. (Thus,
the layered pane lets you specify a Z-order for a component, although this is not something
that you will usually need to do.) The layered pane holds the content pane and the (optional)
menu bar. Although the glass pane and the layered panes are integral to the operation of a
top-level container and serve important purposes, much of what they provide occurs behind
the scene.
The pane with which your application will interact the most is the content pane, because
this is the pane to which you will add visual components. In other words, when you add a
component, such as a button, to a top-level container, you will add it to the content pane.
Therefore, the content pane holds the components that the user interacts with.
Layout Managers
Before you begin writing a Swing program, there is one more thing that you need to be
aware of: the layout manager . The layout manager controls the position of components
within a container. Java offers several layout managers. Most are provided by the AWT
(within java.awt ), but Swing adds a few of its own. All layout managers are instances of a
class that implements the LayoutManager interface. (Some will also implement the Lay-
outManager2 interface.) Here is a list of a few of the layout managers available to the
Swing programmer:
A simple layout that positions components left-to-right, top-to-bottom.
(Positions components right-to-left for some cultural settings.)
FlowLayout
Positions components within the center or the borders of the container.
This is the default layout for a content pane.
BorderLayout
GridLayout
Lays out components within a grid.
Search WWH ::




Custom Search