8.8.3 Using Border Layout
Border Layout is the default layout manager for every content pane. The content pane is the main container in all frames, applets, and dialogs.
A Border Layout has five areas: north, south, east, west, and center.
If you enlarge the window, the center area gets as much of the available space as possible.
The other areas expand only as much as necessary to fill the available space.
By default, a Border Layout creates no gap between the components it manages. The Gap for the components need to be explicitly given using the HGap and VGap properties.
The horizontal gap and vertical gap specify the number of pixels to be put between components.
The components are laid out according to their preferred sizes and the constraints of the container's size. The NORTH and SOUTH components are stretched horizontally; the EAST and WEST components are stretched vertically; the CENTER components fill the rest of space.
Using Bean Builder, the components can be placed in one of the required area by visually dragging/moving and placing them on the particular area (Use the Status Bar, which indicates the mouse position). Alternately the components can be arranged using the Layout Properties , with the container Layout set as Border Layout. Also using the Layout Properties Dialog, the HGap and VGap can be specified.
How to use it
Create a new screen in your project. Click on the screen draw area and right click to view the pop-up menu.
Choose Border Layout from the Layout and click on it. This sets the Border Layout for the container.
The components can be dropped in the desired area (i.e. north, south,etc..) . The position where they are going to be dropped is indicated in the status bar.
Note: When adding a component to a container that uses Border Layout, make sure that the status bar shows the status as for example: Jpanel1 Location:West. Do not rely on the component being added to the center by default. If you find that a component is missing from a container controlled by a Border Layout, make sure that you have specified the component's location and that you didn't put another component in the same location.
You can also drop all the five components in any one of the areas (i.e. north, south,etc..) and then they can be arranged by using the Border Layout Constraints dialog.
Select the Container for which the Border Layout is set and select Layout Properties in the pop-up menu to open up the 'Border Layout Constraints' dialog as shown below. Here you can fix your desired position for each of the components. The Horizontal and Vertical Gap can also be set.
Resizing in Border Layout
The CENTER component cannot be resized. The NORTH and SOUTH component's size can be increased in the vertical direction. The EAST and WEST component's size can be increased in the horizontal direction.
The CENTER component fills up rest of the space.
The layoutProperties for BorderLayout allows us to set the HGap, VGap and component position.
HGap - Horizontal spacing between components.
VGap - Vertical spacing between components.
Position - Position of each component can be set here by selecting the component and its corresponding position in the combobox.
Aligning Beans in BorderLayout
The beans in this layout are aligned to the borders (East, West, North and South directions) automatically. Therefore none of the alignment, spacing or sizing properties are applicable for this type of a layout. When you right click on a multiple selected beans, none of the options are enabled.