Полезная информация

Java AWT

Previous Chapter 19
java.awt Reference
Next
 

GridLayout

Name

GridLayout

[Graphic: Figure from the text]

Description

The GridLayout LayoutManager provides the means to layout components in a grid of rows and columns.

Class Definition

public class java.awt.GridLayout
        extends java.lang.Object
        implements java.awt.LayoutManager, java.io.Serializable
 {
  
// Constructors
  public GridLayout(); (New)
  public GridLayout (int rows, int cols);
  public GridLayout (int rows, int cols, int hgap, int vgap);
  
// Instance Methods
  public void addLayoutComponent (String name, Component component);
  public int getColumns(); (New)
  public int getHgap(); (New)
  public int getRows(); (New)
 
  public int getVgap(); (New)
  public void layoutContainer (Container target); 
  public Dimension minimumLayoutSize (Container target); 
  public Dimension preferredLayoutSize (Container target); 
  public void removeLayoutComponent (Component component); 
  public int setColumns(int cols); (New)
  public int setHgap(int hgap); (New)
  public int setRows(int rows); (New)
 
  public int setVgap(int vgap); (New)
  public String toString();
}

Constructors

GridLayout

public GridLayout() (New)

Description

Constructs a GridLayout object with a default single row and one column per component.

public GridLayout (int rows, int cols)

Parameters

rows

Requested number of rows in container.

cols

Requested number of columns in container.

Description

Constructs a GridLayout object with the requested number of rows and columns. Note that the actual number of rows and columns depends on the number of objects in the layout, not the constructor's parameters.

public GridLayout (int rows, int cols, int hgap, int vgap)

Parameters

rows

Requested number of rows in container.

cols

Requested number of columns in container.

hgap

Horizontal space between each component in a row.

vgap

Vertical space between each row.

Description

Constructs a GridLayout object with the requested number of rows and columns and the values specified as the gaps between each component. Note that the actual number of rows and columns depends on the number of objects in the layout, not the constructor's parameters.

Instance Methods

addLayoutComponent

public void addLayoutComponent (String name, Component component)

Parameters

name

Name of component to add.

component

Actual component being added.

Implements

LayoutManager.addLayoutComponent()

Description

Does nothing.

getColumns

public int getColumns() (New)

Returns

The number of columns.

getHgap

public int getHgap() (New)

Returns

The horizontal gap for this GridLayout instance.

getRows

public int getRows() (New)

Returns

The number of rows.

getVgap

public int getVgap() (New)

Returns

The vertical gap for this GridLayout instance.

layoutContainer

public void layoutContainer (Container target)

Parameters

target

The container that needs to be redrawn.

Implements

LayoutManager.layoutContainer()

Description

Draws the components contained within the target.

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 the minimum size of the 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 the preferred size of the target container.

removeLayoutComponent

public void removeLayoutComponent (Component component)

Parameters

component

Component to stop tracking.

Implements

LayoutManager.removeLayoutComponent()

Description

Does nothing.

setColumns

public void setColumns(int cols) (New)

Parameters

cols

The new number of columns.

Description

Sets the number of columns.

setHgap

public void setHgap(int hgap) (New)

Parameters

hgap

The horizontal gap value.

Description

Sets the horizontal gap between components.

setRows

public void setRows(int rows) (New)

Parameters

rows

The new number of rows.

Description

Sets the number of rows.

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 GridLayout object.

Overrides

Object.toString()

See Also

Component, Container, Dimension, LayoutManager, Object, String


Previous Home Next
GridBagLayout Book Index IllegalComponentStateException (New)

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