- All Implemented Interfaces:
- Serializable,- Cloneable
public class GridBagConstraints extends Object implements Cloneable, Serializable
GridBagConstraints class specifies constraints
 for components that are laid out using the
 GridBagLayout class.- Since:
- 1.0
- See Also:
- GridBagLayout, Serialized Form
- 
Field SummaryFields Modifier and Type Field Description static intABOVE_BASELINEPossible value for theanchorfield.static intABOVE_BASELINE_LEADINGPossible value for theanchorfield.static intABOVE_BASELINE_TRAILINGPossible value for theanchorfield.intanchorThis field is used when the component is smaller than its display area.static intBASELINEPossible value for theanchorfield.static intBASELINE_LEADINGPossible value for theanchorfield.static intBASELINE_TRAILINGPossible value for theanchorfield.static intBELOW_BASELINEPossible value for theanchorfield.static intBELOW_BASELINE_LEADINGPossible value for theanchorfield.static intBELOW_BASELINE_TRAILINGPossible value for theanchorfield.static intBOTHResize the component both horizontally and vertically.static intCENTERPut the component in the center of its display area.static intEASTPut the component on the right side of its display area, centered vertically.intfillThis field is used when the component's display area is larger than the component's requested size.static intFIRST_LINE_ENDPlace the component in the corner of its display area where the first line of text on a page would normally end for the currentComponentOrientation.static intFIRST_LINE_STARTPlace the component in the corner of its display area where the first line of text on a page would normally begin for the currentComponentOrientation.intgridheightSpecifies the number of cells in a column for the component's display area.intgridwidthSpecifies the number of cells in a row for the component's display area.intgridxSpecifies the cell containing the leading edge of the component's display area, where the first cell in a row hasgridx=0.intgridySpecifies the cell at the top of the component's display area, where the topmost cell hasgridy=0.static intHORIZONTALResize the component horizontally but not vertically.InsetsinsetsThis field specifies the external padding of the component, the minimum amount of space between the component and the edges of its display area.intipadxThis field specifies the internal padding of the component, how much space to add to the minimum width of the component.intipadyThis field specifies the internal padding, that is, how much space to add to the minimum height of the component.static intLAST_LINE_ENDPlace the component in the corner of its display area where the last line of text on a page would normally end for the currentComponentOrientation.static intLAST_LINE_STARTPlace the component in the corner of its display area where the last line of text on a page would normally start for the currentComponentOrientation.static intLINE_ENDPlace the component centered along the edge of its display area where lines of text would normally end for the currentComponentOrientation.static intLINE_STARTPlace the component centered along the edge of its display area where lines of text would normally begin for the currentComponentOrientation.static intNONEDo not resize the component.static intNORTHPut the component at the top of its display area, centered horizontally.static intNORTHEASTPut the component at the top-right corner of its display area.static intNORTHWESTPut the component at the top-left corner of its display area.static intPAGE_ENDPlace the component centered along the edge of its display area associated with the end of a page for the currentComponentOrientation.static intPAGE_STARTPlace the component centered along the edge of its display area associated with the start of a page for the currentComponentOrientation.static intRELATIVESpecifies 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).static intREMAINDERSpecifies that this component is the last component in its column or row.static intSOUTHPut the component at the bottom of its display area, centered horizontally.static intSOUTHEASTPut the component at the bottom-right corner of its display area.static intSOUTHWESTPut the component at the bottom-left corner of its display area.static intVERTICALResize the component vertically but not horizontally.doubleweightxSpecifies how to distribute extra horizontal space.doubleweightySpecifies how to distribute extra vertical space.static intWESTPut the component on the left side of its display area, centered vertically.
- 
Constructor SummaryConstructors Constructor Description GridBagConstraints()Creates aGridBagConstraintobject 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 aGridBagConstraintsobject with all of its fields set to the passed-in arguments.
- 
Method Summary
- 
Field Details- 
RELATIVEpublic static final int RELATIVESpecifies 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:
- gridwidth,- gridheight,- gridx,- gridy, Constant Field Values
 
- 
REMAINDERpublic static final int REMAINDERSpecifies that this component is the last component in its column or row.- See Also:
- Constant Field Values
 
- 
NONEpublic static final int NONEDo not resize the component.- See Also:
- Constant Field Values
 
- 
BOTHpublic static final int BOTHResize the component both horizontally and vertically.- See Also:
- Constant Field Values
 
- 
HORIZONTALpublic static final int HORIZONTALResize the component horizontally but not vertically.- See Also:
- Constant Field Values
 
- 
VERTICALpublic static final int VERTICALResize the component vertically but not horizontally.- See Also:
- Constant Field Values
 
- 
CENTERpublic static final int CENTERPut the component in the center of its display area.- See Also:
- Constant Field Values
 
- 
NORTHpublic static final int NORTHPut the component at the top of its display area, centered horizontally.- See Also:
- Constant Field Values
 
- 
NORTHEASTpublic static final int NORTHEASTPut the component at the top-right corner of its display area.- See Also:
- Constant Field Values
 
- 
EASTpublic static final int EASTPut the component on the right side of its display area, centered vertically.- See Also:
- Constant Field Values
 
- 
SOUTHEASTpublic static final int SOUTHEASTPut the component at the bottom-right corner of its display area.- See Also:
- Constant Field Values
 
- 
SOUTHpublic static final int SOUTHPut the component at the bottom of its display area, centered horizontally.- See Also:
- Constant Field Values
 
- 
SOUTHWESTpublic static final int SOUTHWESTPut the component at the bottom-left corner of its display area.- See Also:
- Constant Field Values
 
- 
WESTpublic static final int WESTPut the component on the left side of its display area, centered vertically.- See Also:
- Constant Field Values
 
- 
NORTHWESTpublic static final int NORTHWESTPut the component at the top-left corner of its display area.- See Also:
- Constant Field Values
 
- 
PAGE_STARTpublic static final int PAGE_STARTPlace the component centered along the edge of its display area associated with the start of a page for the currentComponentOrientation. Equal to NORTH for horizontal orientations.- See Also:
- Constant Field Values
 
- 
PAGE_ENDpublic static final int PAGE_ENDPlace the component centered along the edge of its display area associated with the end of a page for the currentComponentOrientation. Equal to SOUTH for horizontal orientations.- See Also:
- Constant Field Values
 
- 
LINE_STARTpublic static final int LINE_STARTPlace the component centered along the edge of its display area where lines of text would normally begin for the currentComponentOrientation. Equal to WEST for horizontal, left-to-right orientations and EAST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
LINE_ENDpublic static final int LINE_ENDPlace the component centered along the edge of its display area where lines of text would normally end for the currentComponentOrientation. Equal to EAST for horizontal, left-to-right orientations and WEST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
FIRST_LINE_STARTpublic static final int FIRST_LINE_STARTPlace the component in the corner of its display area where the first line of text on a page would normally begin for the currentComponentOrientation. Equal to NORTHWEST for horizontal, left-to-right orientations and NORTHEAST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
FIRST_LINE_ENDpublic static final int FIRST_LINE_ENDPlace the component in the corner of its display area where the first line of text on a page would normally end for the currentComponentOrientation. Equal to NORTHEAST for horizontal, left-to-right orientations and NORTHWEST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
LAST_LINE_STARTpublic static final int LAST_LINE_STARTPlace the component in the corner of its display area where the last line of text on a page would normally start for the currentComponentOrientation. Equal to SOUTHWEST for horizontal, left-to-right orientations and SOUTHEAST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
LAST_LINE_ENDpublic static final int LAST_LINE_ENDPlace the component in the corner of its display area where the last line of text on a page would normally end for the currentComponentOrientation. Equal to SOUTHEAST for horizontal, left-to-right orientations and SOUTHWEST for horizontal, right-to-left orientations.- See Also:
- Constant Field Values
 
- 
BASELINEpublic static final int BASELINEPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
BASELINE_LEADINGpublic static final int BASELINE_LEADINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
BASELINE_TRAILINGpublic static final int BASELINE_TRAILINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
ABOVE_BASELINEpublic static final int ABOVE_BASELINEPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
ABOVE_BASELINE_LEADINGpublic static final int ABOVE_BASELINE_LEADINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
ABOVE_BASELINE_TRAILINGpublic static final int ABOVE_BASELINE_TRAILINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
BELOW_BASELINEpublic static final int BELOW_BASELINEPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
BELOW_BASELINE_LEADINGpublic static final int BELOW_BASELINE_LEADINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
BELOW_BASELINE_TRAILINGpublic static final int BELOW_BASELINE_TRAILINGPossible value for theanchorfield. 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
- See Also:
- Constant Field Values
 
- 
gridxpublic int gridxSpecifies the cell containing the leading edge of the component's display area, where the first cell in a row hasgridx=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 valueRELATIVEspecifies 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.gridxshould be a non-negative value.- See Also:
- clone(),- gridy,- ComponentOrientation
 
- 
gridypublic int gridySpecifies the cell at the top of the component's display area, where the topmost cell hasgridy=0. The valueRELATIVEspecifies 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.gridyshould be a non-negative value.
- 
gridwidthpublic int gridwidthSpecifies the number of cells in a row for the component's display area.Use REMAINDERto specify that the component's display area will be fromgridxto the last cell in the row. UseRELATIVEto specify that the component's display area will be fromgridxto the next to the last one in its row.gridwidthshould be non-negative and the default value is 1.- See Also:
- clone(),- gridheight
 
- 
gridheightpublic int gridheightSpecifies the number of cells in a column for the component's display area.Use REMAINDERto specify that the component's display area will be fromgridyto the last cell in the column. UseRELATIVEto specify that the component's display area will be fromgridyto the next to the last one in its column.gridheightshould be a non-negative value and the default value is 1.
- 
weightxpublic double weightxSpecifies how to distribute extra horizontal space.The grid bag layout manager calculates the weight of a column to be the maximum weightxof 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.weightxshould be a non-negative value.
- 
weightypublic double weightySpecifies how to distribute extra vertical space.The grid bag layout manager calculates the weight of a row to be the maximum weightyof 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.weightyshould be a non-negative value.
- 
anchorpublic int anchorThis 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, andNORTHWEST. The orientation relative values are:PAGE_START,PAGE_END,LINE_START,LINE_END,FIRST_LINE_START,FIRST_LINE_END,LAST_LINE_STARTandLAST_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, andBELOW_BASELINE_TRAILING. The default value isCENTER.- See Also:
- clone(),- ComponentOrientation
 
- 
fillpublic int fillThis 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()
 
- 
 
- 
insetsThis 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()
 
- 
ipadxpublic int ipadxThis 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 plusipadxpixels.The default value is 0.
- 
ipadypublic int ipadyThis 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 plusipadypixels.The default value is 0. 
 
- 
- 
Constructor Details- 
GridBagConstraintspublic GridBagConstraints()Creates aGridBagConstraintobject with all of its fields set to their default value.
- 
GridBagConstraintspublic GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady)Creates aGridBagConstraintsobject 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.
- Since:
- 1.2
- See Also:
- gridx,- gridy,- gridwidth,- gridheight,- weightx,- weighty,- anchor,- fill,- insets,- ipadx,- ipady
 
 
- 
- 
Method Details