BorderLayout

The BorderLayout manager has “North”, “East”, “South”, “West”, and “Center” positions where you may place components. The “North”, “East”, “South”, “West” components are placed around the border, and the “Center” component takes up the left-over 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:



The same applet may be invoked 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 Magercise(s):