Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Border Layout


The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an interface that is implemented by all the classes of layout managers. There are following classes that represents the layout managers:

  1. java.awt.BorderLayout
  2. java.awt.FlowLayout
  3. java.awt.GridLayout
  4. java.awt.CardLayout
  5. java.awt.GridBagLayout
  6. javax.swing.BoxLayout
  7. javax.swing.GroupLayout
  8. javax.swing.ScrollPaneLayout
  9. javax.swing.SpringLayout etc.


The BorderLayout is used to arrange the components in five regions: north, south, east, west and center. Each region (area) may contain one component only. It is the default layout of frame or window. The BorderLayout provides five constants for each region:

  1. public static final int NORTH
  2. public static final int SOUTH
  3. public static final int EAST
  4. public static final int WEST
  5. public static final int CENTER

Constructors of BorderLayout class:

  • BorderLayout(): creates a border layout but with no gaps between the components.
  • JBorderLayout(int hgap, int vgap): creates a border layout with the given horizontal and vertical gaps between the components.

Example of BorderLayout class:


  1. import java.awt.*;
  2. import javax.swing.*;
  3. public class Border {
  4. JFrame f;
  5. Border(){
  6.     f=new JFrame();
  7.     JButton b1=new JButton(“NORTH”);;
  8.     JButton b2=new JButton(“SOUTH”);;
  9.     JButton b3=new JButton(“EAST”);;
  10.     JButton b4=new JButton(“WEST”);;
  11.     JButton b5=new JButton(“CENTER”);;
  12.     f.add(b1,BorderLayout.NORTH);
  13.     f.add(b2,BorderLayout.SOUTH);
  14.     f.add(b3,BorderLayout.EAST);
  15.     f.add(b4,BorderLayout.WEST);
  16.     f.add(b5,BorderLayout.CENTER);
  17.     f.setSize(300,300);
  18.     f.setVisible(true);
  19. }
  20. public static void main(String[] args) {
  21.     new Border();
  22. }
  23. }