Place multiple components into one of the regions of a BorderLayout-managed container : BorderLayout « Swing « Java Tutorial






Place multiple components into one of the regions of a BorderLayout-managed container
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MainFrameBorderLayout {
  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.BEFORE_FIRST_LINE);

    frame.add(outerPanel);
    frame.setSize(300, 200);
    frame.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