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.
GridLayout, Control#setLayoutData, Sample code and further information
| Modifier and Type | Field 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 |
| public static final int | FILL_HORIZONTAL
Style bit for |
| public static final int | FILL_VERTICAL
Style bit for |
| public static final int | GRAB_HORIZONTAL
Style bit for |
| public static final int | GRAB_VERTICAL
Style bit for |
| 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 |
| public static final int | HORIZONTAL_ALIGN_CENTER
Style bit for |
| public static final int | HORIZONTAL_ALIGN_END
Style bit for |
| public static final int | HORIZONTAL_ALIGN_FILL
Style bit for |
| 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 |
| public static final int | VERTICAL_ALIGN_CENTER
Style bit for |
| public static final int | VERTICAL_ALIGN_END
Style bit for |
| public static final int | VERTICAL_ALIGN_FILL
Style bit for |
| 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. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| 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. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| pack-priv String | |
| public String | Returns: a string representation of the GridData objectOverrides java. |
| BEGINNING | back 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. | |
| cacheHeight | back to summary |
|---|---|
| pack-priv int cacheHeight | |
| cacheWidth | back to summary |
|---|---|
| pack-priv int cacheWidth | |
| CENTER | back 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. | |
| currentHeight | back to summary |
|---|---|
| pack-priv int currentHeight | |
| currentHhint | back to summary |
|---|---|
| pack-priv int currentHhint | |
| currentWhint | back to summary |
|---|---|
| pack-priv int currentWhint | |
| currentWidth | back to summary |
|---|---|
| pack-priv int currentWidth | |
| defaultHeight | back to summary |
|---|---|
| pack-priv int defaultHeight | |
| defaultHhint | back to summary |
|---|---|
| pack-priv int defaultHhint | |
| defaultWhint | back to summary |
|---|---|
| pack-priv int defaultWhint | |
| defaultWidth | back to summary |
|---|---|
| pack-priv int defaultWidth | |
| END | back 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. | |
| exclude | back to summary |
|---|---|
| public boolean exclude exclude informs the layout to ignore this control when sizing
and positioning controls. If this value is
| |
| FILL | back 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_BOTH | back to summary |
|---|---|
| public static final int FILL_BOTH Style bit for | |
| FILL_HORIZONTAL | back to summary |
|---|---|
| public static final int FILL_HORIZONTAL Style bit for | |
| FILL_VERTICAL | back to summary |
|---|---|
| public static final int FILL_VERTICAL Style bit for | |
| GRAB_HORIZONTAL | back to summary |
|---|---|
| public static final int GRAB_HORIZONTAL Style bit for | |
| GRAB_VERTICAL | back to summary |
|---|---|
| public static final int GRAB_VERTICAL Style bit for | |
| grabExcessHorizontalSpace | back 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
The default value is false.
| |
| grabExcessVerticalSpace | back 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
The default value is false.
| |
| heightHint | back 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. | |
| HORIZONTAL_ALIGN_BEGINNING | back to summary |
|---|---|
| public static final int HORIZONTAL_ALIGN_BEGINNING Style bit for | |
| HORIZONTAL_ALIGN_CENTER | back to summary |
|---|---|
| public static final int HORIZONTAL_ALIGN_CENTER Style bit for | |
| HORIZONTAL_ALIGN_END | back to summary |
|---|---|
| public static final int HORIZONTAL_ALIGN_END Style bit for | |
| HORIZONTAL_ALIGN_FILL | back to summary |
|---|---|
| public static final int HORIZONTAL_ALIGN_FILL Style bit for | |
| horizontalAlignment | back to summary |
|---|---|
| public int horizontalAlignment horizontalAlignment specifies how controls will be positioned horizontally within a cell. The default value is BEGINNING. Possible values are:
| |
| horizontalIndent | back 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. | |
| horizontalSpan | back to summary |
|---|---|
| public int horizontalSpan horizontalSpan specifies the number of column cells that the control will take up. The default value is 1. | |
| minimumHeight | back 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.
| |
| minimumWidth | back 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.
| |
| VERTICAL_ALIGN_BEGINNING | back to summary |
|---|---|
| public static final int VERTICAL_ALIGN_BEGINNING Style bit for | |
| VERTICAL_ALIGN_CENTER | back to summary |
|---|---|
| public static final int VERTICAL_ALIGN_CENTER Style bit for | |
| VERTICAL_ALIGN_END | back to summary |
|---|---|
| public static final int VERTICAL_ALIGN_END Style bit for | |
| VERTICAL_ALIGN_FILL | back to summary |
|---|---|
| public static final int VERTICAL_ALIGN_FILL Style bit for | |
| verticalAlignment | back to summary |
|---|---|
| public int verticalAlignment verticalAlignment specifies how controls will be positioned vertically within a cell. The default value is CENTER. Possible values are:
| |
| verticalIndent | back 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.
| |
| verticalSpan | back to summary |
|---|---|
| public int verticalSpan verticalSpan specifies the number of row cells that the control will take up. The default value is 1. | |
| widthHint | back 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. | |
| GridData | back to summary |
|---|---|
| public GridData() Constructs a new instance of GridData using default values. | |
| GridData | back to summary |
|---|---|
| public GridData(int style) Constructs a new instance based on the GridData style. This constructor is not recommended.
| |
| GridData | back to summary |
|---|---|
| public GridData(int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) Constructs a new instance of GridData according to the parameters.
| |
| GridData | back 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.
| |
| GridData | back 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.
| |
| computeSize | back to summary |
|---|---|
| pack-priv void computeSize(Control control, int wHint, int hHint, boolean flushCache) | |
| flushCache | back to summary |
|---|---|
| pack-priv void flushCache() | |
| getName | back to summary |
|---|---|
| pack-priv String getName() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string containing a concise, human-readable description of the receiver. | |