Combining BorderLayout and GridLayout Managers : BorderLayout « Swing « Java Tutorial

Combining BorderLayout and GridLayout Managers
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class CombinedLayoutManager extends JFrame {

  public static void main(String[] args) {
    CombinedLayoutManager e = new CombinedLayoutManager();
    e.setSize(400, 300);

  public CombinedLayoutManager() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    pane.add(getHeader(), BorderLayout.NORTH);
    pane.add(getTextArea(), BorderLayout.CENTER);
    pane.add(getButtonPanel(), BorderLayout.SOUTH);

  protected JComponent getHeader() {
    JLabel label = new JLabel("Embedded Layout Manager Test", JLabel.CENTER);
    label.setFont(new Font("Courier", Font.BOLD, 24));
    return label;

  protected JComponent getTextArea() {
    return new JTextArea(10, 10);

  protected JComponent getButtonPanel() {
    JPanel inner = new JPanel();
    inner.setLayout(new GridLayout(1, 2, 10, 0));
    inner.add(new JButton("Ok"));
    inner.add(new JButton("Cancel"));
    return inner;


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