Java Reference
In-Depth Information
When using BorderLayout , you add components with constraints to identify in which of
the five locations to place the component. If you don't specify a constraint, the component is
added to the center area. Adding multiple components to the same area shows only the last
component, although technically speaking, the other components are still within the container;
they are just not shown.
There are two constructors for creating the BorderLayout layout manager:
public BorderLayout()
public BorderLayout(int hgap, int vgap)
Unlike FlowLayout , the default gaps for a BorderLayout are zero pixels, meaning the
components are positioned right next to one another.
The constraints to use when adding a component to a BorderLayout -managed container
are constants of the BorderLayout class:
AFTER_LAST_LINE
AFTER_LINE_ENDS
BEFORE_FIRST_LINE
BEFORE_LINE_BEGINS
CENTER
EAST
LINE_END
LINE_START
NORTH
PAGE_END
PAGE_START
SOUTH
WEST
With only five regions to add a component to, you would expect only five constants. As with
FlowLayout , the additional constants deal with proper positioning when the component
orientation is reversed, either horizontally or vertically. For the typical left-to-right, top-to-
bottom orientation, the common set of values is as follows:
AFTER_LAST_LINE , PAGE_END , SOUTH
AFTER_LINE_ENDS , LINE_END , EAST
BEFORE_FIRST_LINE , PAGE_START , NORTH
BEFORE_LINE_BEGINS , LINE_START , WEST
• CENTER
Search WWH ::




Custom Search