BorderLayout

BorderLayout arranges a container's components in areas named North, South, East, West, and Center.

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 tool bar 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,

  1. Select the component you want to position, either in the UI Designer or the Component Tree.
  2. Select the constraints property in the Inspector.
  3. Click the down arrow on the constraints property drop-down list and select the area you want the component to occupy.
  4. Press ENTER or click anywhere else in the Inspector to commit the change to code.
If you use JBuilder's visual design tools to change the layout of an existing container 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.

Each of the five areas can contain only one component (or panel of components), so be careful when changing an existing container to BorderLayout.

Note: 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.