Packages This Package Prev Next Index
§1.1 Class BorderLayout
public class java.awt.BorderLayout
extends java.lang.Object (I-§1.12)
implements java.awt.LayoutManager (II-§1.43)
{
// Constructors
public BorderLayout(); §1.1.1
public BorderLayout(int hgap, int vgap); §1.1.2
// Methods
public void addLayoutComponent(String name, §1.1.3
Component comp);
public void layoutContainer(Container target); §1.1.4
public Dimension minimumLayoutSize(Container target); §1.1.5
public Dimension preferredLayoutSize(Container target); §1.1.6
public void removeLayoutComponent(Component comp); §1.1.7
public String toString(); §1.1.8
}
A border layout lays out a container using members named "North", "South", "East", "West",
and "Center". The components get laid out according to their preferred sizes and the constraints of the container's size. The "North" and "South" components may be stretched horizontally; the "East" and "West" components may be stretched vertically; the "Center"
component may stretch both horizontally and vertically to fill any space left over.
Here is an example of five buttons in an applet laid out using the BorderLayout layout manager:
The code for this applet is the following:
import java.awt.*;
import java.applet.Applet;
public class buttonDir extends Applet {
public void init() {
setLayout(new BorderLayout());
add("North", new Button("North"));
add("South", new Button("South"));
add("East", new Button("East"));
add("West", new Button("West"));
add("Center", new Button("Center"));
}
}
BorderLayout
public BorderLayout()
- Constructs a new border layout.
BorderLayout
public BorderLayout(int hgap, int vgap)
- Creates a new border layout with the specified horizontal and vertical
gaps. The horizontal and vertical gaps specify the space between the components.
- Parameters:
hgap
-
the horizontal gap
vgap
-
the vertical gap
addLayoutComponent
public void addLayoutComponent(String name, Component comp)
- Adds the specified component to this border layout using the indicated tag.
- For border layouts, the tag should be one of "North", "South", "East", "West",
or "Center". Any other tag is ignored.
- Most applications do not call this method directly. This method is called
when a component is added to a container using the two-argument add
method (II-§1.11.3).
- Parameters:
name
-
a tag understood by the layout manager
comp
-
the component to be added
layoutContainer
public void layoutContainer(Container target)
- Lays out the container argument using this border layout.
- This method reshapes the components in the specified container in order to
satisfy the constraints of this BorderLayout object. The "North" and
"South"components, if any, are placed at the top and bottom of the container, respectively. The "West" and "East" components are then placed on
the left and right, respectively. Finally, the "Center" object is placed in any
remaining space in the middle.
- Most applications do not call this method directly. This method is called
when a container calls its layout method (II-§1.11.11).
- Parameters:
target
-
the container in which to do the layout
- See Also:
- Container (II-§1.11).
minimumLayoutSize
public Dimension minimumLayoutSize(Container target)
- Determines the minimum size of the target container using this layout manager.
- This method is called when a container calls its minimumSize method
(II-§1.11.14). Most applications do not call this method directly.
- Parameters:
target
-
the container in which to do the layout
- Returns:
- the minimum dimensions needed to lay out the subcomponents of the
specified container.
- See Also:
- Container (II-§1.11)
preferredLayoutSize (II-§1.1.6).
preferredLayoutSize
public Dimension preferredLayoutSize(Container target)
- Determines the preferred size of the target container using this layout manager.
- This method is called when a container calls its preferredSize method
(II-§1.11.17). Most applications do not call this method directly.
- Parameters:
target
-
the container in which to do the layout
- Returns:
- the preferred dimensions to lay out the subcomponents of the specified container.
- See Also:
- Container (II-§1.11)
minimumLayoutSize (II-§1.1.5).
removeLayoutComponent
public void removeLayoutComponent(Component comp)
- Removes the specified component from this border layout. This method is
called when a container calls its remove (II-§1.11.19) or removeAll
(II-§1.11.20) methods. Most applications do not call this method directly.
- Parameters:
comp
-
the component to be removed
toString
public String toString()
- Returns:
- a string representation of this border layout.
- Overrides:
- toString in class Object (I-§1.12.9).
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com