Learning Java
Custom Search

Previous Next

Border Layout

The Border Layout divides the container into 5 zones, north, south, east, west, and center. The center zone receives all the space not taken up by the other four.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AnimalBorder extends JFrame {
    JButton dog = new JButton("Dog");
    JButton cat = new JButton("Cat");
    JButton bird = new JButton("Bird");
    JButton pig = new JButton("Pig");
    JButton mouse = new JButton("Mouse");

    public AnimalBorder() {
        super("Animal BorderLayout");
        setSize(260, 260);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel pane = new JPanel();
        BorderLayout nature = new BorderLayout();
        pane.setLayout(nature);
        pane.add("North", dog);
        pane.add("South", cat);
        pane.add("East", bird);
        pane.add("West", pig);
        pane.add("Center", mouse);
        add(pane);
        setVisible(true);
    }

    public static void main(String[] arguments) {
        AnimalBorder frame = new AnimalBorder();
    }
}

 

Previous Next

Steps In Learning

Contact us

Copyright © 2008      N. Nelson      All Rights Reserved