APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class GridBagConstraints

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Imports
java.io.Serial

The GridBagConstraints class specifies constraints for components that are laid out using the GridBagLayout class.
Authors
Doug Stein, Bill Spitzak (original NeWS & OLIT implementation)
Since
1.0
See Also
java.awt.GridBagLayout

Field Summary

Modifier and TypeField and Description
public static final int
ABOVE_BASELINE

Possible value for the anchor field.

public static final int
ABOVE_BASELINE_LEADING

Possible value for the anchor field.

public static final int
ABOVE_BASELINE_TRAILING

Possible value for the anchor field.

public int
anchor

This field is used when the component is smaller than its display area.

pack-priv transient int
public static final int
BASELINE

Possible value for the anchor field.

public static final int
BASELINE_LEADING

Possible value for the anchor field.

public static final int
BASELINE_TRAILING

Possible value for the anchor field.

pack-priv transient Component.BaselineResizeBehavior
public static final int
BELOW_BASELINE

Possible value for the anchor field.

public static final int
BELOW_BASELINE_LEADING

Possible value for the anchor field.

public static final int
BELOW_BASELINE_TRAILING

Possible value for the anchor field.

public static final int
BOTH

Resize the component both horizontally and vertically.

public static final int
CENTER

Put the component in the center of its display area.

pack-priv transient int
pack-priv transient int
pack-priv transient int
public static final int
EAST

Put the component on the right side of its display area, centered vertically.

public int
fill

This field is used when the component's display area is larger than the component's requested size.

public static final int
FIRST_LINE_END

Place the component in the corner of its display area where the first line of text on a page would normally end for the current ComponentOrientation.

public static final int
FIRST_LINE_START

Place the component in the corner of its display area where the first line of text on a page would normally begin for the current ComponentOrientation.

public int
gridheight

Specifies the number of cells in a column for the component's display area.

public int
gridwidth

Specifies the number of cells in a row for the component's display area.

public int
gridx

Specifies the cell containing the leading edge of the component's display area, where the first cell in a row has gridx=0.

public int
gridy

Specifies the cell at the top of the component's display area, where the topmost cell has gridy=0.

public static final int
HORIZONTAL

Resize the component horizontally but not vertically.

public Insets
insets

This field specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area.

public int
ipadx

This field specifies the internal padding of the component, how much space to add to the minimum width of the component.

public int
ipady

This field specifies the internal padding, that is, how much space to add to the minimum height of the component.

public static final int
LAST_LINE_END

Place the component in the corner of its display area where the last line of text on a page would normally end for the current ComponentOrientation.

public static final int
LAST_LINE_START

Place the component in the corner of its display area where the last line of text on a page would normally start for the current ComponentOrientation.

public static final int
LINE_END

Place the component centered along the edge of its display area where lines of text would normally end for the current ComponentOrientation.

public static final int
LINE_START

Place the component centered along the edge of its display area where lines of text would normally begin for the current ComponentOrientation.

pack-priv int
minHeight

The minimum height of the component.

pack-priv int
minWidth

The minimum width of the component.

public static final int
NONE

Do not resize the component.

public static final int
NORTH

Put the component at the top of its display area, centered horizontally.

public static final int
NORTHEAST

Put the component at the top-right corner of its display area.

public static final int
NORTHWEST

Put the component at the top-left corner of its display area.

public static final int
PAGE_END

Place the component centered along the edge of its display area associated with the end of a page for the current ComponentOrientation.

public static final int
PAGE_START

Place the component centered along the edge of its display area associated with the start of a page for the current ComponentOrientation.

public static final int
RELATIVE

Specifies that this component is the next-to-last component in its column or row (gridwidth, gridheight), or that this component be placed next to the previously added component (gridx, gridy).

public static final int
REMAINDER

Specifies that this component is the last component in its column or row.

private static final long
serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

public static final int
SOUTH

Put the component at the bottom of its display area, centered horizontally.

public static final int
SOUTHEAST

Put the component at the bottom-right corner of its display area.

public static final int
SOUTHWEST

Put the component at the bottom-left corner of its display area.

pack-priv int
tempHeight

Temporary place holder for the Height of the component.

pack-priv int
tempWidth

Temporary place holder for the Width of the component.

pack-priv int
tempX

Temporary place holder for the x coordinate.

pack-priv int
tempY

Temporary place holder for the y coordinate.

public static final int
VERTICAL

Resize the component vertically but not horizontally.

public double
weightx

Specifies how to distribute extra horizontal space.

public double
weighty

Specifies how to distribute extra vertical space.

public static final int
WEST

Put the component on the left side of its display area, centered vertically.

Constructor Summary

AccessConstructor and Description
public
GridBagConstraints()

Creates a GridBagConstraints object with all of its fields set to their default value.

public
GridBagConstraints(int
The initial gridx value.
gridx
,
int
The initial gridy value.
gridy
,
int
The initial gridwidth value.
gridwidth
,
int
The initial gridheight value.
gridheight
,
double
The initial weightx value.
weightx
,
double
The initial weighty value.
weighty
,
int
The initial anchor value.
anchor
,
int
The initial fill value.
fill
,
Insets
The initial insets value.
insets
,
int
The initial ipadx value.
ipadx
,
int
The initial ipady value.
ipady
)

Creates a GridBagConstraints object with all of its fields set to the passed-in arguments.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a copy of this grid bag constraint
clone
()

Overrides java.lang.Object.clone.

Creates a copy of this grid bag constraint.

pack-priv boolean
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ABOVE_BASELINEback to summary
public static final int ABOVE_BASELINE

Possible value for the anchor field. Specifies that the component should be horizontally centered. Vertically the component is positioned so that its bottom edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
ABOVE_BASELINE_LEADINGback to summary
public static final int ABOVE_BASELINE_LEADING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the leading edge. For components with a left-to-right orientation, the leading edge is the left edge. Vertically the component is positioned so that its bottom edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
ABOVE_BASELINE_TRAILINGback to summary
public static final int ABOVE_BASELINE_TRAILING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the trailing edge. For components with a left-to-right orientation, the trailing edge is the right edge. Vertically the component is positioned so that its bottom edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
anchorback to summary
public int anchor

This field is used when the component is smaller than its display area. It determines where, within the display area, to place the component.

There are three kinds of possible values: orientation relative, baseline relative and absolute. Orientation relative values are interpreted relative to the container's component orientation property, baseline relative values are interpreted relative to the baseline and absolute values are not. The absolute values are: CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, and NORTHWEST. The orientation relative values are: PAGE_START, PAGE_END, LINE_START, LINE_END, FIRST_LINE_START, FIRST_LINE_END, LAST_LINE_START and LAST_LINE_END. The baseline relative values are: BASELINE, BASELINE_LEADING, BASELINE_TRAILING, ABOVE_BASELINE, ABOVE_BASELINE_LEADING, ABOVE_BASELINE_TRAILING, BELOW_BASELINE, BELOW_BASELINE_LEADING, and BELOW_BASELINE_TRAILING. The default value is CENTER.

See Also
clone(), java.awt.ComponentOrientation
ascentback to summary
pack-priv transient int ascent
BASELINEback to summary
public static final int BASELINE

Possible value for the anchor field. Specifies that the component should be horizontally centered and vertically aligned along the baseline of the prevailing row. If the component does not have a baseline it will be vertically centered.

Since
1.6
BASELINE_LEADINGback to summary
public static final int BASELINE_LEADING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the leading edge. For components with a left-to-right orientation, the leading edge is the left edge. Vertically the component is aligned along the baseline of the prevailing row. If the component does not have a baseline it will be vertically centered.

Since
1.6
BASELINE_TRAILINGback to summary
public static final int BASELINE_TRAILING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the trailing edge. For components with a left-to-right orientation, the trailing edge is the right edge. Vertically the component is aligned along the baseline of the prevailing row. If the component does not have a baseline it will be vertically centered.

Since
1.6
baselineResizeBehaviorback to summary
pack-priv transient Component.BaselineResizeBehavior baselineResizeBehavior
BELOW_BASELINEback to summary
public static final int BELOW_BASELINE

Possible value for the anchor field. Specifies that the component should be horizontally centered. Vertically the component is positioned so that its top edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
BELOW_BASELINE_LEADINGback to summary
public static final int BELOW_BASELINE_LEADING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the leading edge. For components with a left-to-right orientation, the leading edge is the left edge. Vertically the component is positioned so that its top edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
BELOW_BASELINE_TRAILINGback to summary
public static final int BELOW_BASELINE_TRAILING

Possible value for the anchor field. Specifies that the component should be horizontally placed along the trailing edge. For components with a left-to-right orientation, the trailing edge is the right edge. Vertically the component is positioned so that its top edge touches the baseline of the starting row. If the starting row does not have a baseline it will be vertically centered.

Since
1.6
BOTHback to summary
public static final int BOTH

Resize the component both horizontally and vertically.

CENTERback to summary
public static final int CENTER

Put the component in the center of its display area.

centerOffsetback to summary
pack-priv transient int centerOffset
centerPaddingback to summary
pack-priv transient int centerPadding
descentback to summary
pack-priv transient int descent
EASTback to summary
public static final int EAST

Put the component on the right side of its display area, centered vertically.

fillback to summary
public int fill

This field is used when the component's display area is larger than the component's requested size. It determines whether to resize the component, and if so, how.

The following values are valid for fill:

  • NONE: Do not resize the component.
  • HORIZONTAL: Make the component wide enough to fill its display area horizontally, but do not change its height.
  • VERTICAL: Make the component tall enough to fill its display area vertically, but do not change its width.
  • BOTH: Make the component fill its display area entirely.

The default value is NONE.

See Also
clone()
FIRST_LINE_ENDback to summary
public static final int FIRST_LINE_END

Place the component in the corner of its display area where the first line of text on a page would normally end for the current ComponentOrientation. Equal to NORTHEAST for horizontal, left-to-right orientations and NORTHWEST for horizontal, right-to-left orientations.

FIRST_LINE_STARTback to summary
public static final int FIRST_LINE_START

Place the component in the corner of its display area where the first line of text on a page would normally begin for the current ComponentOrientation. Equal to NORTHWEST for horizontal, left-to-right orientations and NORTHEAST for horizontal, right-to-left orientations.

gridheightback to summary
public int gridheight

Specifies the number of cells in a column for the component's display area.

Use REMAINDER to specify that the component's display area will be from gridy to the last cell in the column. Use RELATIVE to specify that the component's display area will be from gridy to the next to the last one in its column.

gridheight should be a non-negative value and the default value is 1.

See Also
clone(), java.awt.GridBagConstraints#gridwidth
gridwidthback to summary
public int gridwidth

Specifies the number of cells in a row for the component's display area.

Use REMAINDER to specify that the component's display area will be from gridx to the last cell in the row. Use RELATIVE to specify that the component's display area will be from gridx to the next to the last one in its row.

gridwidth should be non-negative and the default value is 1.

See Also
clone(), java.awt.GridBagConstraints#gridheight
gridxback to summary
public int gridx

Specifies the cell containing the leading edge of the component's display area, where the first cell in a row has gridx=0. The leading edge of a component's display area is its left edge for a horizontal, left-to-right container and its right edge for a horizontal, right-to-left container. The value RELATIVE specifies that the component be placed immediately following the component that was added to the container just before this component was added.

The default value is RELATIVE. gridx should be a non-negative value.

See Also
clone(), java.awt.GridBagConstraints#gridy, java.awt.ComponentOrientation
gridyback to summary
public int gridy

Specifies the cell at the top of the component's display area, where the topmost cell has gridy=0. The value RELATIVE specifies that the component be placed just below the component that was added to the container just before this component was added.

The default value is RELATIVE. gridy should be a non-negative value.

See Also
clone(), java.awt.GridBagConstraints#gridx
HORIZONTALback to summary
public static final int HORIZONTAL

Resize the component horizontally but not vertically.

insetsback to summary
public Insets insets

This field specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area.

The default value is new Insets(0, 0, 0, 0).

See Also
clone()
ipadxback to summary
public int ipadx

This field specifies the internal padding of the component, how much space to add to the minimum width of the component. The width of the component is at least its minimum width plus ipadx pixels.

The default value is 0.

See Also
clone(), java.awt.GridBagConstraints#ipady
ipadyback to summary
public int ipady

This field specifies the internal padding, that is, how much space to add to the minimum height of the component. The height of the component is at least its minimum height plus ipady pixels.

The default value is 0.

See Also
clone(), java.awt.GridBagConstraints#ipadx
LAST_LINE_ENDback to summary
public static final int LAST_LINE_END

Place the component in the corner of its display area where the last line of text on a page would normally end for the current ComponentOrientation. Equal to SOUTHEAST for horizontal, left-to-right orientations and SOUTHWEST for horizontal, right-to-left orientations.

LAST_LINE_STARTback to summary
public static final int LAST_LINE_START

Place the component in the corner of its display area where the last line of text on a page would normally start for the current ComponentOrientation. Equal to SOUTHWEST for horizontal, left-to-right orientations and SOUTHEAST for horizontal, right-to-left orientations.

LINE_ENDback to summary
public static final int LINE_END

Place the component centered along the edge of its display area where lines of text would normally end for the current ComponentOrientation. Equal to EAST for horizontal, left-to-right orientations and WEST for horizontal, right-to-left orientations.

LINE_STARTback to summary
public static final int LINE_START

Place the component centered along the edge of its display area where lines of text would normally begin for the current ComponentOrientation. Equal to WEST for horizontal, left-to-right orientations and EAST for horizontal, right-to-left orientations.

minHeightback to summary
pack-priv int minHeight

The minimum height of the component. It is used to calculate ipadx, where the default will be 0.

See Also
ipadx
minWidthback to summary
pack-priv int minWidth

The minimum width of the component. It is used to calculate ipady, where the default will be 0.

See Also
ipady
NONEback to summary
public static final int NONE

Do not resize the component.

NORTHback to summary
public static final int NORTH

Put the component at the top of its display area, centered horizontally.

NORTHEASTback to summary
public static final int NORTHEAST

Put the component at the top-right corner of its display area.

NORTHWESTback to summary
public static final int NORTHWEST

Put the component at the top-left corner of its display area.

PAGE_ENDback to summary
public static final int PAGE_END

Place the component centered along the edge of its display area associated with the end of a page for the current ComponentOrientation. Equal to SOUTH for horizontal orientations.

PAGE_STARTback to summary
public static final int PAGE_START

Place the component centered along the edge of its display area associated with the start of a page for the current ComponentOrientation. Equal to NORTH for horizontal orientations.

RELATIVEback to summary
public static final int RELATIVE

Specifies that this component is the next-to-last component in its column or row (gridwidth, gridheight), or that this component be placed next to the previously added component (gridx, gridy).

See Also
java.awt.GridBagConstraints#gridwidth, java.awt.GridBagConstraints#gridheight, java.awt.GridBagConstraints#gridx, java.awt.GridBagConstraints#gridy
REMAINDERback to summary
public static final int REMAINDER

Specifies that this component is the last component in its column or row.

serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
SOUTHback to summary
public static final int SOUTH

Put the component at the bottom of its display area, centered horizontally.

SOUTHEASTback to summary
public static final int SOUTHEAST

Put the component at the bottom-right corner of its display area.

SOUTHWESTback to summary
public static final int SOUTHWEST

Put the component at the bottom-left corner of its display area.

tempHeightback to summary
pack-priv int tempHeight

Temporary place holder for the Height of the component.

tempWidthback to summary
pack-priv int tempWidth

Temporary place holder for the Width of the component.

tempXback to summary
pack-priv int tempX

Temporary place holder for the x coordinate.

tempYback to summary
pack-priv int tempY

Temporary place holder for the y coordinate.

VERTICALback to summary
public static final int VERTICAL

Resize the component vertically but not horizontally.

weightxback to summary
public double weightx

Specifies how to distribute extra horizontal space.

The grid bag layout manager calculates the weight of a column to be the maximum weightx of all the components in a column. If the resulting layout is smaller horizontally than the area it needs to fill, the extra space is distributed to each column in proportion to its weight. A column that has a weight of zero receives no extra space.

If all the weights are zero, all the extra space appears between the grids of the cell and the left and right edges.

The default value of this field is 0. weightx should be a non-negative value.

See Also
clone(), java.awt.GridBagConstraints#weighty
weightyback to summary
public double weighty

Specifies how to distribute extra vertical space.

The grid bag layout manager calculates the weight of a row to be the maximum weighty of all the components in a row. If the resulting layout is smaller vertically than the area it needs to fill, the extra space is distributed to each row in proportion to its weight. A row that has a weight of zero receives no extra space.

If all the weights are zero, all the extra space appears between the grids of the cell and the top and bottom edges.

The default value of this field is 0. weighty should be a non-negative value.

See Also
clone(), java.awt.GridBagConstraints#weightx
WESTback to summary
public static final int WEST

Put the component on the left side of its display area, centered vertically.

Constructor Detail

GridBagConstraintsback to summary
public GridBagConstraints()

Creates a GridBagConstraints object with all of its fields set to their default value.

GridBagConstraintsback to summary
public GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady)

Creates a GridBagConstraints object with all of its fields set to the passed-in arguments.

Note

Because the use of this constructor hinders readability of source code, this constructor should only be used by automatic source code generation tools.

Parameters
gridx:int

The initial gridx value.

gridy:int

The initial gridy value.

gridwidth:int

The initial gridwidth value.

gridheight:int

The initial gridheight value.

weightx:double

The initial weightx value.

weighty:double

The initial weighty value.

anchor:int

The initial anchor value.

fill:int

The initial fill value.

insets:Insets

The initial insets value.

ipadx:int

The initial ipadx value.

ipady:int

The initial ipady value.

Since
1.2
See Also
java.awt.GridBagConstraints#gridx, java.awt.GridBagConstraints#gridy, java.awt.GridBagConstraints#gridwidth, java.awt.GridBagConstraints#gridheight, java.awt.GridBagConstraints#weightx, java.awt.GridBagConstraints#weighty, java.awt.GridBagConstraints#anchor, java.awt.GridBagConstraints#fill, java.awt.GridBagConstraints#insets, java.awt.GridBagConstraints#ipadx, java.awt.GridBagConstraints#ipady

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Creates a copy of this grid bag constraint.

Returns:Object

a copy of this grid bag constraint

isVerticallyResizableback to summary
pack-priv boolean isVerticallyResizable()