Java Swing Tutorials - Herong's Tutorial Examples - Version 4.11, by Dr. Herong Yang
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:
Sample programs listed in this section have been tested with JDK 1.3.1 to 1.8.0.
Last update: 2014.
Table of Contents
Introduction of Java Swing Package
Graphics Environment of the Local System
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
►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
JEditorPane - The Editor Pane Class