Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.BorderLayout extends java.lang.Object implements java.awt.LayoutManager { // Constructors public BorderLayout(); public BorderLayout(int hgap, int vgap); // Methods public void addLayoutComponent(String name, Component comp); public void layoutContainer(Container target); public Dimension minimumLayoutSize(Container target); public Dimension preferredLayoutSize(Container target); public void removeLayoutComponent(Component comp); public String toString(); }
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")); } }
public BorderLayout()Constructs a new border layout.
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.
Parameter Description hgap the horizontal gap vgap the vertical gap
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 .
Parameter Description name a tag understood by the layout manager comp the component to be added
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 .
Parameter Description target the container in which to do the layout See Also: Container .
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 . Most applications do not call this method directly.
Return Value:
Returns the minimum dimensions needed to lay out the subcomponents of the specified container.
Parameter Description target the container in which to do the layout See Also: Container 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 . Most applications do not call this method directly.
Return Value:
Returns the preferred dimensions to lay out the subcomponents of the specified container.
Parameter Description target the container in which to do the layout See Also: Container minimumLayoutSize .
public void removeLayoutComponent(Component comp)Removes the specified component from this border layout. This method is called when a container calls its remove or removeAll methods. Most applications do not call this method directly.
Parameter Description comp the component to be removed
public String toString()Return Value:
Returns a string representation of this border layout.
Overrides:
toString in class Object .