start page | rating of books | rating of authors | reviews | copyrights

Java AWT

Previous Chapter 19
java.awt Reference
Next
 

BorderLayout

Name

BorderLayout

[Graphic: Figure from the text]

Description

BorderLayout is a LayoutManager that provides the means to lay out components along the edges of a container. It divides the container into five regions, named North, East, South, West, and Center. Normally you won't call the LayoutManager's methods yourself. When you add() a Component to a Container, the Container calls the addLayoutComponent() method of its LayoutManager.

Class Definition

public class java.awt.BorderLayout
    extends java.lang.Object
    implements java.awt.LayoutManager2, java.io.Serializable {
  // Constants
  public final static String CENTER; (New)
  public final static String EAST; (New)
  public final static String NORTH; (New)
  public final static String SOUTH; (New)
  public final static String WEST; (New)
  
  // Constructors
  public BorderLayout();
  public BorderLayout (int hgap, int vgap);
  
  // Instance Methods
  public void addLayoutComponent (Component comp, Object constraints); (New)
  public void addLayoutComponent (String name, Component component); (Deprecated)
  public int getHgap(); (New)
  public abstract float getLayoutAlignmentX(Container target); (New)
  public abstract float getLayoutAlignmentY(Container target); (New)
  public int getVgap(); (New)
  public abstract void invalidateLayout(Container target); (New)
  
  public void layoutContainer (Container target); 
  public abstract Dimension maximumLayoutSize(Container target); (New)
  public Dimension minimumLayoutSize (Container target); 
  public Dimension preferredLayoutSize (Container target); 
  public void removeLayoutComponent (Component component); 
  public void setHgap (int hgap); (New)
  public void setVgap (int vgap); (New)
  public String toString();
}

Constants

CENTER

public final static String CENTER

A constant representing center orientation.

EAST

public final static String EAST

A constant representing east orientation.

NORTH

public final static String NORTH

A constant representing north orientation.

SOUTH

public final static String SOUTH

A constant representing south orientation.

WEST

public final static String WEST

A constant representing west orientation.

Constructors

BorderLayout

public BorderLayout()

Description

Constructs a BorderLayout object.

public BorderLayout (int hgap, int vgap)

Parameters

hgap

Horizontal space between each component in the container.

vgap

Vertical space between each component in the container.

Description

Constructs a BorderLayout object with the values specified as the gaps between each component in the container managed by this instance of BorderLayout.

Instance Methods

addLayoutComponent

public void addLayoutComponent (Component comp, Object constraints) (New)

Parameters

comp

The component being added.

constraints

An object describing the constraints on this component.

Implements

LayoutManager2.addLayoutComponent()

Description

Adds the component comp to a container subject to the given constraints. This is a more general version of addLayoutComponent(String, Component) method. It corresponds to java.awt.Container's add(Component, Object) method. In practice, it is used the same in version 1.1 as in Java 1.0.2, except with the parameters swapped:

Panel p = new Panel(new BorderLayout());
p.add(new Button("OK"), BorderLayout.SOUTH);

addLayoutComponent

public void addLayoutComponent (String name, Component component) (Deprecated)

Parameters

name

Name of region to add component to.

component

Actual component being added.

Implements

LayoutManager.addLayoutComponent()

Description

Adds a component to a container in region name. This has been replaced in version 1.1 with the more general addLayoutComponent(Component, Object).

getHgap

public int getHgap() (New)

Returns

The horizontal gap for this BorderLayout instance.

getLayoutAlignmentX

public abstract float getLayoutAlignmentX (Container target) (New)

Parameters

target

The container to inspect.

Returns

The value .5 for all containers.

Description

This method returns the preferred alignment of the given container target. A return value of 0 is left aligned, .5 is centered, and 1 is right aligned.

getLayoutAlignmentY

public abstract float getLayoutAlignmentY (Container target) (New)

Parameters

target

The container to inspect.

Returns

The value .5 for all containers.

Description

This method returns the preferred alignment of the given container target. A return value of 0 is top aligned, .5 is centered, and 1 is bottom aligned.

getVgap

public int getVgap() (New)

Returns

The vertical gap for this BorderLayout instance.

invalidateLayout

public abstract void invalidateLayout (Container target) (New)

Parameters

target

The container to invalidate.

Description

Does nothing.

layoutContainer

public void layoutContainer (Container target)

Parameters

target

The container that needs to be redrawn.

Implements

LayoutManager.layoutContainer()

Description

Draws components contained within target.

maximumLayoutSize

public abstract Dimension maximumLayoutSize (Container target) (New)

Parameters

target

The container to inspect.

Returns

A Dimension whose horizontal and vertical components are Integer.MAX_VALUE.

Description

For BorderLayout, a maximal Dimension is always returned.

minimumLayoutSize

public Dimension minimumLayoutSize (Container target)

Parameters

target

The container whose size needs to be calculated.

Returns

Minimum Dimension of the container target.

Implements

LayoutManager.minimumLayoutSize()

Description

Calculates minimum size of target. container.

preferredLayoutSize

public Dimension preferredLayoutSize (Container target)

Parameters

target

The container whose size needs to be calculated.

Returns

Preferred Dimension of the container target.

Implements

LayoutManager.preferredLayoutSize()

Description

Calculates preferred size of target container.

removeLayoutComponent

public void removeLayoutComponent (Component component)

Parameters

component

Component to stop tracking.

Implements

LayoutManager.removeLayoutComponent()

Description

Removes component from any internal tracking systems.

setHgap

public void setHgap (int hgap) (New)

Parameters

hgap

The horizontal gap value.

Description

Sets the horizontal gap between components.

setVgap

public void setVgap (int vgap) (New)

Parameters

vgap

The vertical gap value.

Description

Sets the vertical gap between components.

toString

public String toString()

Returns

A string representation of the BorderLayout object.

Overrides

Object.toString()

See Also

Component, Container, Dimension, LayoutManager, LayoutManager2, Object, String


Previous Home Next
Adjustable (New) Book Index Button

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java