java.awt

Class BorderLayout

public class BorderLayout extends Object implements LayoutManager2, Serializable

This class implements a layout manager that positions components in certain sectors of the parent container.
Field Summary
static StringAFTER_LAST_LINE
The constant indicating the position after the last line of the layout.
static StringAFTER_LINE_ENDS
The constant indicating the position after the last item of the layout.
static StringBEFORE_FIRST_LINE
The constant indicating the position before the first line of the layout.
static StringBEFORE_LINE_BEGINS
The constant indicating the position before the first item of the layout.
static StringCENTER
Constant indicating the center of the container
static StringEAST
Constant indicating the right side of the container
static StringLINE_END
The constant indicating the position after the last item of the layout.
static StringLINE_START
The constant indicating the position before the first item of the layout.
static StringNORTH
Constant indicating the top of the container
static StringPAGE_END
The constant indicating the position after the last line of the layout.
static StringPAGE_START
The constant indicating the position before the first line of the layout.
static StringSOUTH
Constant indicating the bottom of the container
static StringWEST
Constant indicating the left side of the container
Constructor Summary
BorderLayout()
Initializes a new instance of BorderLayout with no horiztonal or vertical gaps between components.
BorderLayout(int hgap, int vgap)
Initializes a new instance of BorderLayout with the specified horiztonal and vertical gaps between components.
Method Summary
voidaddLayoutComponent(Component component, Object constraints)
Adds a component to the layout in the specified constraint position, which must be one of the string constants defined in this class.
voidaddLayoutComponent(String constraints, Component component)
Adds a component to the layout in the specified constraint position, which must be one of the string constants defined in this class.
ObjectgetConstraints(Component c)
Return the constraint corresponding to a component in this layout.
intgetHgap()
Returns the horitzontal gap value.
floatgetLayoutAlignmentX(Container parent)
Returns the X axis alignment, which is a float indicating where along the X axis this container wishs to position its layout.
floatgetLayoutAlignmentY(Container parent)
Returns the Y axis alignment, which is a float indicating where along the Y axis this container wishs to position its layout.
ComponentgetLayoutComponent(Object constraints)
Return the component at the indicated location, or null if no component is at that location.
ComponentgetLayoutComponent(Container container, Object constraints)
Return the component at the specified location, which must be one of the absolute constants such as CENTER or SOUTH.
intgetVgap()
Returns the vertical gap value.
voidinvalidateLayout(Container parent)
Instructs this object to discard any layout information it might have cached.
voidlayoutContainer(Container target)
Lays out the specified container according to the constraints in this object.
DimensionmaximumLayoutSize(Container target)
Returns the maximum size of the specified container using this layout.
DimensionminimumLayoutSize(Container target)
Returns the minimum size of the specified container using this layout.
DimensionpreferredLayoutSize(Container target)
Returns the preferred size of the specified container using this layout.
voidremoveLayoutComponent(Component component)
Removes the specified component from the layout.
voidsetHgap(int hgap)
Sets the horizontal gap to the specified value.
voidsetVgap(int vgap)
Sets the vertical gap to the specified value.
StringtoString()
Returns a string representation of this layout manager.

Field Detail

AFTER_LAST_LINE

public static final String AFTER_LAST_LINE
The constant indicating the position after the last line of the layout. The exact position depends on the writing system: For a top-to-bottom orientation, it is the same as {@link #SOUTH}, for a bottom-to-top orientation, it is the same as {@link #NORTH}.

This constant is an older name for {@link #PAGE_END} which has exactly the same value.

Since: 1.2

AFTER_LINE_ENDS

public static final String AFTER_LINE_ENDS
The constant indicating the position after the last item of the layout. The exact position depends on the writing system: For a left-to-right orientation, it is the same as {@link #EAST}, for a right-to-left orientation, it is the same as {@link #WEST}.

This constant is an older name for {@link #LINE_END} which has exactly the same value.

Since: 1.2

BEFORE_FIRST_LINE

public static final String BEFORE_FIRST_LINE
The constant indicating the position before the first line of the layout. The exact position depends on the writing system: For a top-to-bottom orientation, it is the same as {@link #NORTH}, for a bottom-to-top orientation, it is the same as {@link #SOUTH}.

This constant is an older name for {@link #PAGE_START} which has exactly the same value.

Since: 1.2

BEFORE_LINE_BEGINS

public static final String BEFORE_LINE_BEGINS
The constant indicating the position before the first item of the layout. The exact position depends on the writing system: For a left-to-right orientation, it is the same as {@link #WEST}, for a right-to-left orientation, it is the same as {@link #EAST}.

This constant is an older name for {@link #LINE_START} which has exactly the same value.

Since: 1.2

CENTER

public static final String CENTER
Constant indicating the center of the container

EAST

public static final String EAST
Constant indicating the right side of the container

LINE_END

public static final String LINE_END
The constant indicating the position after the last item of the layout. The exact position depends on the writing system: For a left-to-right orientation, it is the same as {@link #EAST}, for a right-to-left orientation, it is the same as {@link #WEST}.

Since: 1.4

LINE_START

public static final String LINE_START
The constant indicating the position before the first item of the layout. The exact position depends on the writing system: For a left-to-right orientation, it is the same as {@link #WEST}, for a right-to-left orientation, it is the same as {@link #EAST}.

Since: 1.4

NORTH

public static final String NORTH
Constant indicating the top of the container

PAGE_END

public static final String PAGE_END
The constant indicating the position after the last line of the layout. The exact position depends on the writing system: For a top-to-bottom orientation, it is the same as {@link #SOUTH}, for a bottom-to-top orientation, it is the same as {@link #NORTH}.

Since: 1.4

PAGE_START

public static final String PAGE_START
The constant indicating the position before the first line of the layout. The exact position depends on the writing system: For a top-to-bottom orientation, it is the same as {@link #NORTH}, for a bottom-to-top orientation, it is the same as {@link #SOUTH}.

Since: 1.4

SOUTH

public static final String SOUTH
Constant indicating the bottom of the container

WEST

public static final String WEST
Constant indicating the left side of the container

Constructor Detail

BorderLayout

public BorderLayout()
Initializes a new instance of BorderLayout with no horiztonal or vertical gaps between components.

BorderLayout

public BorderLayout(int hgap, int vgap)
Initializes a new instance of BorderLayout with the specified horiztonal and vertical gaps between components.

Parameters: hgap The horizontal gap between components. vgap The vertical gap between components.

Method Detail

addLayoutComponent

public void addLayoutComponent(Component component, Object constraints)
Adds a component to the layout in the specified constraint position, which must be one of the string constants defined in this class.

Parameters: component The component to add. constraints The constraint string.

Throws: IllegalArgumentException If the constraint object is not a string, or is not one of the specified constants in this class.

addLayoutComponent

public void addLayoutComponent(String constraints, Component component)

Deprecated: This method is deprecated in favor of addLayoutComponent(Component, Object).

Adds a component to the layout in the specified constraint position, which must be one of the string constants defined in this class.

Parameters: constraints The constraint string. component The component to add.

Throws: IllegalArgumentException If the constraint object is not one of the specified constants in this class.

getConstraints

public Object getConstraints(Component c)
Return the constraint corresponding to a component in this layout. If the component is null, or is not in this layout, returns null. Otherwise, this will return one of the constraint constants defined in this class.

Parameters: c the component

Returns: the constraint, or null

Since: 1.5

getHgap

public int getHgap()
Returns the horitzontal gap value.

Returns: The horitzontal gap value.

getLayoutAlignmentX

public float getLayoutAlignmentX(Container parent)
Returns the X axis alignment, which is a float indicating where along the X axis this container wishs to position its layout. 0 indicates align to the left, 1 indicates align to the right, and 0.5 indicates align to the center.

Parameters: parent The parent container.

Returns: The X alignment value.

getLayoutAlignmentY

public float getLayoutAlignmentY(Container parent)
Returns the Y axis alignment, which is a float indicating where along the Y axis this container wishs to position its layout. 0 indicates align to the top, 1 indicates align to the bottom, and 0.5 indicates align to the center.

Parameters: parent The parent container.

Returns: The Y alignment value.

getLayoutComponent

public Component getLayoutComponent(Object constraints)
Return the component at the indicated location, or null if no component is at that location. The constraints argument must be one of the location constants specified by this class.

Parameters: constraints the location

Returns: the component at that location, or null

Throws: IllegalArgumentException if the constraints argument is not recognized

Since: 1.5

getLayoutComponent

public Component getLayoutComponent(Container container, Object constraints)
Return the component at the specified location, which must be one of the absolute constants such as CENTER or SOUTH. The container's orientation is used to map this location to the correct corresponding component, so for instance in a right-to-left container, a request for the EAST component could return the LINE_END component. This will return null if no component is available at the given location.

Parameters: container the container whose orientation is used constraints the absolute location of the component

Returns: the component at the location, or null

Throws: IllegalArgumentException if the constraint is not recognized

getVgap

public int getVgap()
Returns the vertical gap value.

Returns: The vertical gap value.

invalidateLayout

public void invalidateLayout(Container parent)
Instructs this object to discard any layout information it might have cached.

Parameters: parent The parent container.

layoutContainer

public void layoutContainer(Container target)
Lays out the specified container according to the constraints in this object.

Parameters: target The container to lay out.

maximumLayoutSize

public Dimension maximumLayoutSize(Container target)
Returns the maximum size of the specified container using this layout.

Parameters: target The container to calculate the maximum size for.

Returns: The maximum size of the container

minimumLayoutSize

public Dimension minimumLayoutSize(Container target)
Returns the minimum size of the specified container using this layout.

Parameters: target The container to calculate the minimum size for.

Returns: The minimum size of the container

preferredLayoutSize

public Dimension preferredLayoutSize(Container target)
Returns the preferred size of the specified container using this layout.

Parameters: target The container to calculate the preferred size for.

Returns: The preferred size of the container

removeLayoutComponent

public void removeLayoutComponent(Component component)
Removes the specified component from the layout.

Parameters: component The component to remove from the layout.

setHgap

public void setHgap(int hgap)
Sets the horizontal gap to the specified value.

Parameters: hgap The new horizontal gap.

setVgap

public void setVgap(int vgap)
Sets the vertical gap to the specified value.

Parameters: vgap The new vertical gap value.

toString

public String toString()
Returns a string representation of this layout manager.

Returns: A string representation of this object.