Border
Home Up Border Card Flow Grid Null

 

Border Layout Manager

The BorderLayout manager can be invoked in one of two ways:

  1.   setLayout (new BorderLayout());

    There are five areas where components can be added.  These five areas are "North" (the top of the window), "South" (the bottom of the window), "East" (the right of the window), "West" (the left of the window), and "Center" (the center of the window). 
  2.   setLayout (new BorderLayout(int, int));

    The two parameters specify the horizontal gap in pixels between each pair of regions and the vertical gap in pixels between each pair of regions.

In order to display a component, one must "add" it to the appropriate region.

Example

In the code below, five buttons are created and placed in each of the five possible drawing areas.  Run the program to see what is displayed.  Try commenting out any one of the add statements to learn what happens when an area is not used.

import java.awt.*;
import java.applet.*;          
public class Border extends Applet
{
	public void init ()
	{
		setLayout(new BorderLayout());          
		add ("North",  new Button("1"));
		add ("South",  new Button("2"));
		add ("East",   new Button("3"));
		add ("West",   new Button("4"));
		add ("Center", new Button("5"));
	}
		          
}        
What You'll See