Java Reference
In-Depth Information
Border Layout
Border layouts , which are created by using the BorderLayout class in java.awt , divide a
container into five sections: north, south, east, west, and center. The five areas of Figure
11.4 show how these sections are arranged.
FIGURE 11.4
Components
arranged under
border layout.
Under border layout, the components in the four compass points take up as much space
as they need—the center gets whatever space is left over. Ordinarily, this results in an
arrangement with a large central component and four thin components around it.
11
A border layout is created with either the BorderLayout () or BorderLayout( int ,
int ) constructors. The first constructor creates a border layout with no gap between any
of the components. The second constructor specifies the horizontal gap and vertical gap,
respectively.
After you create a border layout and set it up as a container's layout manager, compo-
nents are added using a call to the add() method that's different from what you have
seen previously:
add( Component, String )
The first argument is the component that should be added to the container.
The second argument is a BorderLayout class variable that indicates to which part of the
border layout to assign the component. The variables NORTH , SOUTH , EAST , WEST , and
CENTER can be used.
The second argument to this method is the component that should be added to the con-
tainer.
Search WWH ::




Custom Search