Home
01 Getting Started
02 Concepts
03 Variables & Data Types
04 Control Logic
05 Modifiers
06 GUI
07 Other Useful Classes
08 Handling Events
09 Handling Exceptions
10 Project 01 - Mortg Calc
11 More On Applets
12 Layout Manager
a Absolute Positioning
b Flow Layout
c Border Layout
d Grid Layout
e Grid Bag Layout
f Mixing Layout Managers
13 Project 02 - Calculator
14 Threads
15 Project 03 - Wake Up
16 File I/O
17 Project 04 - File I/O
Expanded Table of Contents
Debugging Hints
HTML Review
Download Samples
|
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
|
|