Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Top
Back
Next
Online Training
shadowSearchFAQFeedback

BorderLayout

The BorderLayout manager has “North”, “East”, “South”, “West”, and “Center” positions where you can place components. The “North”, “East”, “South”, “West” components are placed around the border, and the “Center” component takes up the leftover space in the middle. The components are automatically resized when the area of the layout is changed. For example, here is an applet with two buttons, a Label, a TextField, and a TextArea:



You can invoke the same applet within a smaller region without changing the applet:



Corrsponding source code:

import java.awt.*;
import java.applet.Applet;
public class BorderLayoutTest extends Applet {
    public void init() {
        setLayout(new BorderLayout());
        add("North", new Label("A Header Maybe"));
        add("South",new TextField("Type some text here"));
        add("West",new Button("QUIT"));
        add("East", new Button("HELP"));
        add("Center",new TextArea("Some random text\nin a TextArea"));
    }
}

See also How to Use BorderLayout.

Related exercise(s):