A BorderLayout divides the space into five regions: North, West, South, East and Centre. : BorderLayout « Swing « Java Tutorial






import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class BorderExample {
  public static void main(String[] args) {
    JPanel panel = new JPanel(new BorderLayout());
    JPanel top = new JPanel();

    top.setBackground(Color.gray);
    top.setPreferredSize(new Dimension(250, 150));
    panel.add(top);

    panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40)));
    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

  }
}








14.86.BorderLayout
14.86.1.What is the BorderLayoutWhat is the BorderLayout
14.86.2.A BorderLayout divides the space into five regions: North, West, South, East and Centre.
14.86.3.Using a BorderLayout ManagerUsing a BorderLayout Manager
14.86.4.A typical usage of a border layout manager.A typical usage of a border layout manager.
14.86.5.Place multiple components into one of the regions of a BorderLayout-managed containerPlace multiple components into one of the regions of a BorderLayout-managed container
14.86.6.Combining BorderLayout and GridLayout ManagersCombining BorderLayout and GridLayout Managers