BorderLayout
arranges a container's components in areas named North, South, East, West, and Center.
BorderLayout
by default.
Example
BorderLayout
is good for forcing components to one or more edges of a container and for filling up the center of the container with a component. It is also the layout you want to use to cause a single component to completely fill its container.
You will probably find BorderLayout
to be the most useful layout manager for the larger containers in your UI. By nesting a panel inside each area of the BorderLayout
, then populating each of those panels with other panels of various layouts, you can achieve quite complicated UI designs.
For more information on using nested layouts, see Using nested panels and layouts.
Components are positioned in one of five areas within a BorderLayout
, based on the constraints
property. You can set the constraints
property for the component in the Inspector to one of the following values:
North, South, East, West, or Center.
For example, to put a toolbar across the top of a BorderLayout
container, you could create a FlowLayout
panel of buttons and place it in the North area of the container. You do this by selecting the panel and choosing North for its constraints
property in the Inspector.
To set the constraints
property,
constraints
property in the Inspector.
constraints
property drop-down list and select the area you want the component to occupy.
If you use JBuilder's visual design tools to change the layout of a container from another layout to BorderLayout
, the components near the edges automatically move to fill the closest edge. A component near the center may be set to Center. If a component moves to an unintended location, you can correct the constraints
property in the Inspector, or drag the component around in the UI designer.
As you drag a component around in a BorderLayout
container, the UI designer displays a rectangle to demonstrate which area of the container the component will snap to if you drop it.
Each of the five areas can contain only one component (or panel of components), so be careful when changing an existing container to BorderLayout
.
XYLayout
first to move the components to their approximate intended positions, with only one component near each edge.
BorderLayout
ignores the order in which you add components to the container.
By default, a BorderLayout
puts no gap between the components it manages. However, you can use the Inspector to specify the horizontal or vertical gap in pixels for a layout associated with a container.
To modify the gap surrounding BorderLayout
components, select the BorderLayout
object in the component tree (displayed immediately below the container it controls), then modify the pixel value in the Inspector for the hgap
and vgap
properties.