java.lang.Object
|
+--java.awt.BorderLayout
A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region is identified by a corresponding constant:
NORTH, SOUTH, EAST,
WEST, and CENTER. When adding a
component to a container with a border layout, use one of these
five constants, for example:
Panel p = new Panel();
p.setLayout(new BorderLayout());
p.add(new Button("Okay"), BorderLayout.SOUTH);
As a convenience, BorderLayout interprets the absence of a string
specification the same as the constant CENTER:
Panel p2 = new Panel();
p2.setLayout(new BorderLayout());
p2.add(new TextArea()); // Same as p.add(new TextArea(), BorderLayout.CENTER);
In addition, BorderLayout supports four relative positioning constants,
BEFORE_FIRST_LINE, AFTER_LAST_LINE,
BEFORE_LINE_BEGINS, and AFTER_LINE_ENDS.
In a container whose ComponentOrientation is set to
ComponentOrientation.LEFT_TO_RIGHT, these constants map to
NORTH, SOUTH, WEST, and
EAST, respectively
Mixing the two types of constants can lead to unpredicable results. If
you use both types, the relative constants will take precedence.
For example, if you add components using both the NORTH
and BEFORE_FIRST_LINE constants in a container whose
orientation is LEFT_TO_RIGHT, only the
BEFORE_FIRST_LINE will be layed out.
NOTE: Currently (in the Java 2 platform v1.2), BorderLayout does not support vertical
orientations. The isVertical setting on the container's
ComponentOrientation is not respected.
The components are 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 as follows:
import java.awt.*;
import java.applet.Applet;
public class buttonDir extends Applet {
public void init() {
setLayout(new BorderLayout());
add(new Button("North"), BorderLayout.NORTH);
add(new Button("South"), BorderLayout.SOUTH);
add(new Button("East"), BorderLayout.EAST);
add(new Button("West"), BorderLayout.WEST);
add(new Button("Center"), BorderLayout.CENTER);
}
}
Container.add(String, Component),
ComponentOrientation, Serialized Form
| Field Summary | |
static String |
AFTER_LAST_LINE
copy-> AFTER_LAST_LINE
|
static String |
AFTER_LINE_ENDS
copy-> AFTER_LINE_ENDS
|
static String |
BEFORE_FIRST_LINE
copy-> BEFORE_FIRST_LINE
|
static String |
BEFORE_LINE_BEGINS
copy-> BEFORE_LINE_BEGINS
|
static String |
CENTER
copy-> CENTER
|
static String |
EAST
copy-> EAST
|
static String |
NORTH
copy-> NORTH
|
static String |
SOUTH
copy-> SOUTH
|
static String |
WEST
copy-> WEST
|
| Constructor Summary | |
BorderLayout
copy-> new BorderLayout()copy-> <BorderLayout var> = new BorderLayout();
|
|
BorderLayout
copy-> new BorderLayout(, )copy-> <BorderLayout var> = new BorderLayout(<int hgap>, <int vgap>);
|
|
| Method Summary | |
void |
addLayoutComponent(Component comp,
Object constraints)
copy-> .addLayoutComponent(, )copy-> <BorderLayout>.addLayoutComponent(<Component comp>, <Object constraints>);
|
void |
addLayoutComponent(String name,
Component comp)
copy-> .addLayoutComponent(, )copy-> <BorderLayout>.addLayoutComponent(<String name>, <Component comp>);
|
int |
getHgap()
copy-> .getHgap()copy-> <int var>=<BorderLayout>.getHgap();
|
float |
getLayoutAlignmentX(Container parent)
copy-> .getLayoutAlignmentX( )copy-> <float var>=<BorderLayout>.getLayoutAlignmentX(<Container parent>);
|
float |
getLayoutAlignmentY(Container parent)
copy-> .getLayoutAlignmentY( )copy-> <float var>=<BorderLayout>.getLayoutAlignmentY(<Container parent>);
|
int |
getVgap()
copy-> .getVgap()copy-> <int var>=<BorderLayout>.getVgap();
|
void |
invalidateLayout(Container target)
copy-> .invalidateLayout( )copy-> <BorderLayout>.invalidateLayout(<Container target>);
|
void |
layoutContainer(Container target)
copy-> .layoutContainer( )copy-> <BorderLayout>.layoutContainer(<Container target>);
|
Dimension |
maximumLayoutSize(Container target)
copy-> .maximumLayoutSize( )copy-> <Dimension var>=<BorderLayout>.maximumLayoutSize(<Container target>);
|
Dimension |
minimumLayoutSize(Container target)
copy-> .minimumLayoutSize( )copy-> <Dimension var>=<BorderLayout>.minimumLayoutSize(<Container target>);
|
Dimension |
preferredLayoutSize(Container target)
copy-> .preferredLayoutSize( )copy-> <Dimension var>=<BorderLayout>.preferredLayoutSize(<Container target>);
|
void |
removeLayoutComponent(Component comp)
copy-> .removeLayoutComponent( )copy-> <BorderLayout>.removeLayoutComponent(<Component comp>);
|
void |
setHgap(int hgap)
copy-> .setHgap( )copy-> <BorderLayout>.setHgap(<int hgap>);
|
void |
setVgap(int vgap)
copy-> .setVgap( )copy-> <BorderLayout>.setVgap(<int vgap>);
|
String |
toString()
copy-> .toString()copy-> <String var>=<BorderLayout>.toString(); |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |