### GridLayout

GridLayout is one of the more powerful and complex layouts. GridLayout lays out widgets in a grid, providing many configurable parameters that control the sizing behavior of the grid rows and columns when the composite is resized.

The GridLayout defines API that controls the overall strategy of the layout. The most important attribute is numColumns, which determines the horizontal size of the grid. Typically you decide on this value when you first design your window's appearance. The order of the widgets in the grid is the same as the order in which you create them. To change the order of the widgets in the grid, you can use the Control methods moveAbove(Control) and moveBelow(Control). These methods allow widgets to be inserted before or after each other in the layout. (The "above" and "below" refer to the widget Z ordering, not to the location in the grid itself).

The following table summarizes the configurable parameters for a GridLayout:

Attribute | Description
--- | ---
horizontalSpacing | Number of pixels between the right edge of one cell and the left edge of its neighboring cell.
makeColumnsEqualWidth | Specifies whether all columns should be forced to the same width.
marginWidth | Number of pixels used for margin on the right and left edge of the grid.
marginHeight | Number of pixels used for margin on the top and bottom edge of the grid.
numColumns | Number of columns that should be used to make the grid.
verticalSpacing | Number of pixels between the bottom edge of one cell and the top edge of its neighboring cell.

GridLayout supports many other layout parameters for each widget in the grid. These properties are specified in a GridData object. You must set a GridData as the layout data for each widget in the grid.

The GridData class defines style constants that let you specify commonly used combinations of layout parameters in the GridData constructor. You can also set these attributes individually using the public methods in GridData.

You can achieve some highly dynamic and complex layouts using the GridData. Tweaking these values for different widgets in the grid can produce many different combinations of layouts. The ability to allow widgets to span across cells produces many layouts that don't even look like a grid.

The following table summarizes the configurable parameters for GridData. See Understanding layouts in SWT for further description and example screen captures using the various grid parameters.

Attribute | Description
--- | ---
grabExcessHorizontalSpace | Specifies whether a cell should grow to use any extra horizontal space available in the grid. After the cell sizes in the grid are calculated based on the widgets and their grid data, any extra space remaining in the Composite will be allocated to those cells that grab excess space.
grabExcessVerticalSpace | Specifies whether a cell should grow to use any extra vertical space available in the grid.
heightHint | Specifies a minimum height for the widget (and therefore for the row that contains it).
horizontalAlignment | Can be one of BEGINNING, CENTER, END, FILL. FILL means that the widget will be sized to take up the entire width of its grid cell.
horizontalIndent | Number of pixels between the widget and the left edge of its grid cell.
horizontalSpan | Specifies the number of columns in the grid that the widget should span. By default, a widget takes up one cell in the grid. It can take additional cells horizontally by increasing this value.
verticalAlignment | Can be one of BEGINNING, CENTER, END, FILL. FILL means that the widget will be sized to take up the entire height of its grid cell.
verticalSpan | Specifies the number of rows in the grid that the widget should span. By default, a widget takes up one cell in the grid. It can take additional cells vertically by increasing this value.
widthHint | Specifies a minimum width for the widget (and therefore the column that contains it).