Top Description Fields Constructors Methods
org.eclipse.swt.layout

public final Class GridData

extends Object
Class Inheritance
Imports
org.eclipse.swt.*, org.eclipse.swt.graphics.*, org.eclipse.swt.widgets.*

GridData is the layout data object associated with GridLayout. To set a GridData object into a control, you use the Control.setLayoutData(Object) method.

There are two ways to create a GridData object with certain fields set. The first is to set the fields directly, like this:

		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		button1.setLayoutData(gridData);

		gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.verticalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		gridData.horizontalSpan = 2;
		button2.setLayoutData(gridData);
The second is to take advantage of GridData convenience constructors, for example:
     button1.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, true, false));
     button2.setLayoutData(new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1));

Note

Do not reuse GridData objects. Every control in a Composite that is managed by a GridLayout must have a unique GridData object. If the layout data for a control in a GridLayout is null at layout time, a unique GridData object is created for it.

See Also
GridLayout, Control#setLayoutData, Sample code and further information

Field Summary

Modifier and TypeField and Description
public static final int
BEGINNING

Value for horizontalAlignment or verticalAlignment.

pack-priv int
pack-priv int
public static final int
CENTER

Value for horizontalAlignment or verticalAlignment.

pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
public static final int
END

Value for horizontalAlignment or verticalAlignment.

public boolean
exclude

exclude informs the layout to ignore this control when sizing and positioning controls.

public static final int
FILL

Value for horizontalAlignment or verticalAlignment.

public static final int
FILL_BOTH

Style bit for new GridData(int) to resize the control to fill the cell horizontally and vertically and to fit the remaining horizontal and vertical space.

public static final int
FILL_HORIZONTAL

Style bit for new GridData(int) to resize the control to fill the cell horizontally and to fit the remaining horizontal space.

public static final int
FILL_VERTICAL

Style bit for new GridData(int) to resize the control to fill the cell vertically and to fit the remaining vertical space.

public static final int
GRAB_HORIZONTAL

Style bit for new GridData(int) to resize the control to fit the remaining horizontal space.

public static final int
GRAB_VERTICAL

Style bit for new GridData(int) to resize the control to fit the remaining vertical space.

public boolean
grabExcessHorizontalSpace

grabExcessHorizontalSpace specifies whether the width of the cell changes depending on the size of the parent Composite.

public boolean
grabExcessVerticalSpace

grabExcessVerticalSpace specifies whether the height of the cell changes depending on the size of the parent Composite.

public int
heightHint

heightHint specifies the preferred height in points.

public static final int
HORIZONTAL_ALIGN_BEGINNING

Style bit for new GridData(int) to position the control at the left of the cell.

public static final int
HORIZONTAL_ALIGN_CENTER

Style bit for new GridData(int) to position the control in the horizontal center of the cell.

public static final int
HORIZONTAL_ALIGN_END

Style bit for new GridData(int) to position the control at the right of the cell.

public static final int
HORIZONTAL_ALIGN_FILL

Style bit for new GridData(int) to resize the control to fill the cell horizontally.

public int
horizontalAlignment

horizontalAlignment specifies how controls will be positioned horizontally within a cell.

public int
horizontalIndent

horizontalIndent specifies the number of points of indentation that will be placed along the left side of the cell.

public int
horizontalSpan

horizontalSpan specifies the number of column cells that the control will take up.

public int
minimumHeight

minimumHeight specifies the minimum height in points.

public int
minimumWidth

minimumWidth specifies the minimum width in points.

public static final int
VERTICAL_ALIGN_BEGINNING

Style bit for new GridData(int).

public static final int
VERTICAL_ALIGN_CENTER

Style bit for new GridData(int) to position the control in the vertical center of the cell.

public static final int
VERTICAL_ALIGN_END

Style bit for new GridData(int) to position the control at the bottom of the cell.

public static final int
VERTICAL_ALIGN_FILL

Style bit for new GridData(int) to resize the control to fill the cell vertically.

public int
verticalAlignment

verticalAlignment specifies how controls will be positioned vertically within a cell.

public int
verticalIndent

verticalIndent specifies the number of points of indentation that will be placed along the top side of the cell.

public int
verticalSpan

verticalSpan specifies the number of row cells that the control will take up.

public int
widthHint

widthHint specifies the preferred width in points.

Constructor Summary

AccessConstructor and Description
public
GridData()

Constructs a new instance of GridData using default values.

public
GridData(int
the GridData style
style
)

Constructs a new instance based on the GridData style.

public
GridData(int
how control will be positioned horizontally within a cell, one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
horizontalAlignment
,
int
how control will be positioned vertically within a cell, one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
verticalAlignment
,
boolean
whether cell will be made wide enough to fit the remaining horizontal space
grabExcessHorizontalSpace
,
boolean
whether cell will be made high enough to fit the remaining vertical space
grabExcessVerticalSpace
)

Constructs a new instance of GridData according to the parameters.

public
GridData(int
how control will be positioned horizontally within a cell, one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
horizontalAlignment
,
int
how control will be positioned vertically within a cell, one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
verticalAlignment
,
boolean
whether cell will be made wide enough to fit the remaining horizontal space
grabExcessHorizontalSpace
,
boolean
whether cell will be made high enough to fit the remaining vertical space
grabExcessVerticalSpace
,
int
the number of column cells that the control will take up
horizontalSpan
,
int
the number of row cells that the control will take up
verticalSpan
)

Constructs a new instance of GridData according to the parameters.

public
GridData(int
a minimum width for the column
width
,
int
a minimum height for the row
height
)

Constructs a new instance of GridData according to the parameters.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
computeSize(Control control, int wHint, int hHint, boolean flushCache)

pack-priv void
pack-priv String
public String

Returns:

a string representation of the GridData object
toString
()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

BEGINNINGback to summary
public static final int BEGINNING

Value for horizontalAlignment or verticalAlignment. Position the control at the top or left of the cell. Not recommended. Use SWT.BEGINNING, SWT.TOP or SWT.LEFT instead.

cacheHeightback to summary
pack-priv int cacheHeight
cacheWidthback to summary
pack-priv int cacheWidth
CENTERback to summary
public static final int CENTER

Value for horizontalAlignment or verticalAlignment. Position the control in the vertical or horizontal center of the cell Not recommended. Use SWT.CENTER instead.

currentHeightback to summary
pack-priv int currentHeight
currentHhintback to summary
pack-priv int currentHhint
currentWhintback to summary
pack-priv int currentWhint
currentWidthback to summary
pack-priv int currentWidth
defaultHeightback to summary
pack-priv int defaultHeight
defaultHhintback to summary
pack-priv int defaultHhint
defaultWhintback to summary
pack-priv int defaultWhint
defaultWidthback to summary
pack-priv int defaultWidth
ENDback to summary
public static final int END

Value for horizontalAlignment or verticalAlignment. Position the control at the bottom or right of the cell Not recommended. Use SWT.END, SWT.BOTTOM or SWT.RIGHT instead.

excludeback to summary
public boolean exclude

exclude informs the layout to ignore this control when sizing and positioning controls. If this value is true, the size and position of the control will not be managed by the layout. If this value is false, the size and position of the control will be computed and assigned. The default value is false.

Since
3.1
FILLback to summary
public static final int FILL

Value for horizontalAlignment or verticalAlignment. Resize the control to fill the cell horizontally or vertically. Not recommended. Use SWT.FILL instead.

FILL_BOTHback to summary
public static final int FILL_BOTH

Style bit for new GridData(int) to resize the control to fill the cell horizontally and vertically and to fit the remaining horizontal and vertical space. FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL Not recommended. Use new GridData(SWT.FILL, SWT.FILL, true, true) instead.

FILL_HORIZONTALback to summary
public static final int FILL_HORIZONTAL

Style bit for new GridData(int) to resize the control to fill the cell horizontally and to fit the remaining horizontal space. FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL Not recommended. Use new GridData(SWT.FILL, int, true, boolean) instead.

FILL_VERTICALback to summary
public static final int FILL_VERTICAL

Style bit for new GridData(int) to resize the control to fill the cell vertically and to fit the remaining vertical space. FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL Not recommended. Use new GridData(int, SWT.FILL, boolean, true) instead.

GRAB_HORIZONTALback to summary
public static final int GRAB_HORIZONTAL

Style bit for new GridData(int) to resize the control to fit the remaining horizontal space. Not recommended. Use new GridData(int, int, true, boolean) instead.

GRAB_VERTICALback to summary
public static final int GRAB_VERTICAL

Style bit for new GridData(int) to resize the control to fit the remaining vertical space. Not recommended. Use new GridData(int, int, boolean, true) instead.

grabExcessHorizontalSpaceback to summary
public boolean grabExcessHorizontalSpace

grabExcessHorizontalSpace specifies whether the width of the cell changes depending on the size of the parent Composite. If grabExcessHorizontalSpace is true, the following rules apply to the width of the cell:

  • If extra horizontal space is available in the parent, the cell will grow to be wider than its preferred width. The new width will be "preferred width + delta" where delta is the extra horizontal space divided by the number of grabbing columns.
  • If there is not enough horizontal space available in the parent, the cell will shrink until it reaches its minimum width as specified by GridData.minimumWidth. The new width will be the maximum of "minimumWidth" and "preferred width - delta", where delta is the amount of space missing divided by the number of grabbing columns.
  • If the parent is packed, the cell will be its preferred width as specified by GridData.widthHint.
  • If the control spans multiple columns and there are no other grabbing controls in any of the spanned columns, the last column in the span will grab the extra space. If there is at least one other grabbing control in the span, the grabbing will be spread over the columns already marked as grabExcessHorizontalSpace.

The default value is false.

See Also
GridData#minimumWidth, GridData#widthHint
grabExcessVerticalSpaceback to summary
public boolean grabExcessVerticalSpace

grabExcessVerticalSpace specifies whether the height of the cell changes depending on the size of the parent Composite. If grabExcessVerticalSpace is true, the following rules apply to the height of the cell:

  • If extra vertical space is available in the parent, the cell will grow to be taller than its preferred height. The new height will be "preferred height + delta" where delta is the extra vertical space divided by the number of grabbing rows.
  • If there is not enough vertical space available in the parent, the cell will shrink until it reaches its minimum height as specified by GridData.minimumHeight. The new height will be the maximum of "minimumHeight" and "preferred height - delta", where delta is the amount of space missing divided by the number of grabbing rows.
  • If the parent is packed, the cell will be its preferred height as specified by GridData.heightHint.
  • If the control spans multiple rows and there are no other grabbing controls in any of the spanned rows, the last row in the span will grab the extra space. If there is at least one other grabbing control in the span, the grabbing will be spread over the rows already marked as grabExcessVerticalSpace.

The default value is false.

See Also
GridData#minimumHeight, GridData#heightHint
heightHintback to summary
public int heightHint

heightHint specifies the preferred height in points. This value is the hHint passed into Control.computeSize(int, int, boolean) to determine the preferred size of the control. The default value is SWT.DEFAULT.

See Also
Control#computeSize(int, int, boolean)
HORIZONTAL_ALIGN_BEGINNINGback to summary
public static final int HORIZONTAL_ALIGN_BEGINNING

Style bit for new GridData(int) to position the control at the left of the cell. Not recommended. Use new GridData(SWT.BEGINNING, int, boolean, boolean) instead.

HORIZONTAL_ALIGN_CENTERback to summary
public static final int HORIZONTAL_ALIGN_CENTER

Style bit for new GridData(int) to position the control in the horizontal center of the cell. Not recommended. Use new GridData(SWT.CENTER, int, boolean, boolean) instead.

HORIZONTAL_ALIGN_ENDback to summary
public static final int HORIZONTAL_ALIGN_END

Style bit for new GridData(int) to position the control at the right of the cell. Not recommended. Use new GridData(SWT.END, int, boolean, boolean) instead.

HORIZONTAL_ALIGN_FILLback to summary
public static final int HORIZONTAL_ALIGN_FILL

Style bit for new GridData(int) to resize the control to fill the cell horizontally. Not recommended. Use new GridData(SWT.FILL, int, boolean, boolean) instead.

horizontalAlignmentback to summary
public int horizontalAlignment

horizontalAlignment specifies how controls will be positioned horizontally within a cell. The default value is BEGINNING. Possible values are:

  • SWT.BEGINNING (or SWT.LEFT): Position the control at the left of the cell
  • SWT.CENTER: Position the control in the horizontal center of the cell
  • SWT.END (or SWT.RIGHT): Position the control at the right of the cell
  • SWT.FILL: Resize the control to fill the cell horizontally
horizontalIndentback to summary
public int horizontalIndent

horizontalIndent specifies the number of points of indentation that will be placed along the left side of the cell. The default value is 0.

horizontalSpanback to summary
public int horizontalSpan

horizontalSpan specifies the number of column cells that the control will take up. The default value is 1.

minimumHeightback to summary
public int minimumHeight

minimumHeight specifies the minimum height in points. This value applies only if grabExcessVerticalSpace is true. A value of SWT.DEFAULT means that the minimum height will be the result of Control.computeSize(int, int, boolean) where hHint is determined by GridData.heightHint. The default value is 0.

Since
3.1
See Also
Control#computeSize(int, int, boolean), GridData#heightHint
minimumWidthback to summary
public int minimumWidth

minimumWidth specifies the minimum width in points. This value applies only if grabExcessHorizontalSpace is true. A value of SWT.DEFAULT means that the minimum width will be the result of Control.computeSize(int, int, boolean) where wHint is determined by GridData.widthHint. The default value is 0.

Since
3.1
See Also
Control#computeSize(int, int, boolean), GridData#widthHint
VERTICAL_ALIGN_BEGINNINGback to summary
public static final int VERTICAL_ALIGN_BEGINNING

Style bit for new GridData(int). Position the control at the top of the cell. Not recommended. Use new GridData(int, SWT.BEGINNING, boolean, boolean) instead.

VERTICAL_ALIGN_CENTERback to summary
public static final int VERTICAL_ALIGN_CENTER

Style bit for new GridData(int) to position the control in the vertical center of the cell. Not recommended. Use new GridData(int, SWT.CENTER, boolean, boolean) instead.

VERTICAL_ALIGN_ENDback to summary
public static final int VERTICAL_ALIGN_END

Style bit for new GridData(int) to position the control at the bottom of the cell. Not recommended. Use new GridData(int, SWT.END, boolean, boolean) instead.

VERTICAL_ALIGN_FILLback to summary
public static final int VERTICAL_ALIGN_FILL

Style bit for new GridData(int) to resize the control to fill the cell vertically. Not recommended. Use new GridData(int, SWT.FILL, boolean, boolean) instead

verticalAlignmentback to summary
public int verticalAlignment

verticalAlignment specifies how controls will be positioned vertically within a cell. The default value is CENTER. Possible values are:

  • SWT.BEGINNING (or SWT.TOP): Position the control at the top of the cell
  • SWT.CENTER: Position the control in the vertical center of the cell
  • SWT.END (or SWT.BOTTOM): Position the control at the bottom of the cell
  • SWT.FILL: Resize the control to fill the cell vertically
verticalIndentback to summary
public int verticalIndent

verticalIndent specifies the number of points of indentation that will be placed along the top side of the cell. The default value is 0.

Since
3.1
verticalSpanback to summary
public int verticalSpan

verticalSpan specifies the number of row cells that the control will take up. The default value is 1.

widthHintback to summary
public int widthHint

widthHint specifies the preferred width in points. This value is the wHint passed into Control.computeSize(int, int, boolean) to determine the preferred size of the control. The default value is SWT.DEFAULT.

See Also
Control#computeSize(int, int, boolean)

Constructor Detail

GridDataback to summary
public GridData()

Constructs a new instance of GridData using default values.

GridDataback to summary
public GridData(int style)

Constructs a new instance based on the GridData style. This constructor is not recommended.

Parameters
style:int

the GridData style

GridDataback to summary
public GridData(int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace)

Constructs a new instance of GridData according to the parameters.

Parameters
horizontalAlignment:int

how control will be positioned horizontally within a cell, one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL

verticalAlignment:int

how control will be positioned vertically within a cell, one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL

grabExcessHorizontalSpace:boolean

whether cell will be made wide enough to fit the remaining horizontal space

grabExcessVerticalSpace:boolean

whether cell will be made high enough to fit the remaining vertical space

Since
3.0
GridDataback to summary
public GridData(int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan, int verticalSpan)

Constructs a new instance of GridData according to the parameters.

Parameters
horizontalAlignment:int

how control will be positioned horizontally within a cell, one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL

verticalAlignment:int

how control will be positioned vertically within a cell, one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL

grabExcessHorizontalSpace:boolean

whether cell will be made wide enough to fit the remaining horizontal space

grabExcessVerticalSpace:boolean

whether cell will be made high enough to fit the remaining vertical space

horizontalSpan:int

the number of column cells that the control will take up

verticalSpan:int

the number of row cells that the control will take up

Since
3.0
GridDataback to summary
public GridData(int width, int height)

Constructs a new instance of GridData according to the parameters. A value of SWT.DEFAULT indicates that no minimum width or no minimum height is specified.

Parameters
width:int

a minimum width for the column

height:int

a minimum height for the row

Since
3.0

Method Detail

computeSizeback to summary
pack-priv void computeSize(Control control, int wHint, int hHint, boolean flushCache)
flushCacheback to summary
pack-priv void flushCache()
getNameback to summary
pack-priv String getName()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.

Returns:String

a string representation of the GridData object

Annotations
@Override