java.awt.BorderLayout - Border Layout

This section provides a tutorial example on how to create a BorderLayout to layout components in a container. BorderLayout has 5 fixed sections - north, south, west, east and center.

java.awt.BorderLayout - A very simple layout that:

Here is an example program I wrote to test the BorderLayout:

/* BorderLayoutTest.java
 * Copyright (c) 2014, HerongYang.com, All Rights Reserved.
 */
import java.awt.*;
import javax.swing.*;
public class BorderLayoutTest {
   public static void main(String[] a) {
      JFrame myFrame = new JFrame("FlowLayout Test");
      myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container myPane = myFrame.getContentPane();
      
      myPane.setLayout(new BorderLayout());
      myPane.add(new JButton("North"), BorderLayout.NORTH);
      myPane.add(new JButton("South"), BorderLayout.SOUTH);
      myPane.add(new JButton("East"), BorderLayout.EAST);
      myPane.add(new JButton("West"), BorderLayout.WEST);
      myPane.add(new JButton(new ImageIcon("java.gif")), 
         BorderLayout.CENTER);
      myFrame.pack();
      myFrame.setVisible(true);
   }
}

If you run this example, you will get:
Layout - BorderLayout

Sample programs listed in this section have been tested with JDK 1.3.1 to 1.8.0.

Last update: 2014.

Table of Contents

 About This Book

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

Layout of Components in a Container

 What Is Layout?

java.awt.BorderLayout - Border Layout

 java.awt.FlowLayout - Flow Layout

 java.awt.BoxLayout - Box Layout

 java.awt.GridLayout - Grid Layout

 java.awt.GridBagLayout - Grid Bag Layout

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

 References

 PDF Printing Version