Java Reference
In-Depth Information
BorderLayout
The layout manager BorderLayout places components into five regions
within the container: North, South, East, West, and Center. Figure 5-23
displays an application with five buttons, one in each region, placed using
the BorderLayout layout manager.
components added
using BorderLayout
layout manager
BorderLayout
regions
FIGURE 5-23
Components are added to the container by specifying their geographical
placement using the add() method, as in the following line of code:
add(myButton, BorderLayout.SOUTH);
An alternate form adds and constructs a button with a caption, as shown in the
following line of code:
add(“South”, new Button(“Okay”));
Up to five components can be added in any order, but only one component can
be added to each region. Additional components added to a region will replace
whatever component is in a region. The components placed in the North and
South regions extend horizontally to the edge of the container and are as tall as
the tallest component. The components in the East and West regions expand
vertically between the North and South regions and are as wide as the widest
component. The Center component expands to take up all the remaining space.
If a North, South, East, or West component is not present, the adjacent compo-
nents fill the space. If a Center component is not present, the region is left blank.
With BorderLayout, you also can specify the number of pixels between
components, using the following line of code:
setLayout(new BorderLayout(9,7));
This line of code instructs the layout manager to use the BorderLayout with nine
pixels horizontally and seven pixels vertically between components.
 
Search WWH ::




Custom Search