public class

GridBagConstraints

extends Object
implements Serializable Cloneable
java.lang.Object
   ↳ java.awt.GridBagConstraints

Class Overview

The GridBagConstraints class specifies constraints for components that are laid out using the GridBagLayout class.

See Also

Summary

Constants
int ABOVE_BASELINE Possible value for the anchor field.
int ABOVE_BASELINE_LEADING Possible value for the anchor field.
int ABOVE_BASELINE_TRAILING Possible value for the anchor field.
int BASELINE Possible value for the anchor field.
int BASELINE_LEADING Possible value for the anchor field.
int BASELINE_TRAILING Possible value for the anchor field.
int BELOW_BASELINE Possible value for the anchor field.
int BELOW_BASELINE_LEADING Possible value for the anchor field.
int BELOW_BASELINE_TRAILING Possible value for the anchor field.
int BOTH Resize the component both horizontally and vertically.
int CENTER Put the component in the center of its display area.
int EAST Put the component on the right side of its display area, centered vertically.
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 ComponentOrienation.
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 ComponentOrienation.
int HORIZONTAL Resize the component horizontally but not vertically.
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 ComponentOrienation.
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 ComponentOrienation.
int LINE_END Place the component centered along the edge of its display area where lines of text would normally end for the current ComponentOrienation.
int LINE_START Place the component centered along the edge of its display area where lines of text would normally begin for the current ComponentOrienation.
int NONE Do not resize the component.
int NORTH Put the component at the top of its display area, centered horizontally.
int NORTHEAST Put the component at the top-right corner of its display area.
int NORTHWEST Put the component at the top-left corner of its display area.
int PAGE_END Place the component centered along the edge of its display area associated with the end of a page for the current ComponentOrienation.
int PAGE_START Place the component centered along the edge of its display area associated with the start of a page for the current ComponentOrienation.
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).
int REMAINDER Specifies that this component is the last component in its column or row.
int SOUTH Put the component at the bottom of its display area, centered horizontally.
int SOUTHEAST Put the component at the bottom-right corner of its display area.
int SOUTHWEST Put the component at the bottom-left corner of its display area.
int VERTICAL Resize the component vertically but not horizontally.
int WEST Put the component on the left side of its display area, centered vertically.
Fields
public int anchor This field is used when the component is smaller than its display area.
public int fill This field is used when the component's display area is larger than the component's requested size.
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 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 double weightx Specifies how to distribute extra horizontal space.
public double weighty Specifies how to distribute extra vertical space.
Public Constructors
GridBagConstraints()
Creates a GridBagConstraint object with all of its fields set to their default value.
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.
Public Methods
Object clone()
Creates a copy of this grid bag constraint.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

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.

Constant Value: 1024 (0x00000400)

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.

Constant Value: 1280 (0x00000500)

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.

Constant Value: 1536 (0x00000600)

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.

Constant Value: 256 (0x00000100)

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.

Constant Value: 512 (0x00000200)

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.

Constant Value: 768 (0x00000300)

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.

Constant Value: 1792 (0x00000700)

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.

Constant Value: 2048 (0x00000800)

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.

Constant Value: 2304 (0x00000900)

public static final int BOTH

Resize the component both horizontally and vertically.

Constant Value: 1 (0x00000001)

public static final int CENTER

Put the component in the center of its display area.

Constant Value: 10 (0x0000000a)

public static final int EAST

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

Constant Value: 13 (0x0000000d)

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 ComponentOrienation. Equal to NORTHEAST for horizontal, left-to-right orientations and NORTHWEST for horizontal, right-to-left orientations.

Constant Value: 24 (0x00000018)

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 ComponentOrienation. Equal to NORTHWEST for horizontal, left-to-right orientations and NORTHEAST for horizontal, right-to-left orientations.

Constant Value: 23 (0x00000017)

public static final int HORIZONTAL

Resize the component horizontally but not vertically.

Constant Value: 2 (0x00000002)

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 ComponentOrienation. Equal to SOUTHEAST for horizontal, left-to-right orientations and SOUTHWEST for horizontal, right-to-left orientations.

Constant Value: 26 (0x0000001a)

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 ComponentOrienation. Equal to SOUTHWEST for horizontal, left-to-right orientations and SOUTHEAST for horizontal, right-to-left orientations.

Constant Value: 25 (0x00000019)

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 ComponentOrienation. Equal to EAST for horizontal, left-to-right orientations and WEST for horizontal, right-to-left orientations.

Constant Value: 22 (0x00000016)

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 ComponentOrienation. Equal to WEST for horizontal, left-to-right orientations and EAST for horizontal, right-to-left orientations.

Constant Value: 21 (0x00000015)

public static final int NONE

Do not resize the component.

Constant Value: 0 (0x00000000)

public static final int NORTH

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

Constant Value: 11 (0x0000000b)

public static final int NORTHEAST

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

Constant Value: 12 (0x0000000c)

public static final int NORTHWEST

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

Constant Value: 18 (0x00000012)

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 ComponentOrienation. Equal to SOUTH for horizontal orientations.

Constant Value: 20 (0x00000014)

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 ComponentOrienation. Equal to NORTH for horizontal orientations.

Constant Value: 19 (0x00000013)

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).

Constant Value: -1 (0xffffffff)

public static final int REMAINDER

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

Constant Value: 0 (0x00000000)

public static final int SOUTH

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

Constant Value: 15 (0x0000000f)

public static final int SOUTHEAST

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

Constant Value: 14 (0x0000000e)

public static final int SOUTHWEST

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

Constant Value: 16 (0x00000010)

public static final int VERTICAL

Resize the component vertically but not horizontally.

Constant Value: 3 (0x00000003)

public static final int WEST

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

Constant Value: 17 (0x00000011)

Fields

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 relvative 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.@serial

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.@serial

See Also

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.@serial

See Also

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.@serial

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.@serial

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.@serial

See Also

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).@serial

See Also

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.@serial

See Also

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.@serial

See Also

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.@serial

See Also

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.@serial

See Also

Public Constructors

public GridBagConstraints ()

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

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 The initial gridx value.
gridy The initial gridy value.
gridwidth The initial gridwidth value.
gridheight The initial gridheight value.
weightx The initial weightx value.
weighty The initial weighty value.
anchor The initial anchor value.
fill The initial fill value.
insets The initial insets value.
ipadx The initial ipadx value.
ipady The initial ipady value.

Public Methods

public Object clone ()

Creates a copy of this grid bag constraint.

Returns
  • a copy of this grid bag constraint