Class Grid
A rectangular grid that can contain text, html, or a child
Widget within its cells. It must be
resized explicitly to the desired number of rows and columns.

Example
public class GridExample implements EntryPoint {
public void onModuleLoad() {
// Grids must be sized explicitly, though they can be resized later.
Grid g = new Grid(5, 5);
// Put some values in the grid cells.
for (int row = 0; row < 5; ++row) {
for (int col = 0; col < 5; ++col)
g.setText(row, col, "" + row + ", " + col);
}
// Just for good measure, let's put a button in the center.
g.setWidget(2, 2, new Button("Does nothing, but could"));
// You can use the CellFormatter to affect the layout of the grid's cells.
g.getCellFormatter().setWidth(0, 2, "256px");
RootPanel.get().add(g);
}
}
Fields
Constructors
Methods
Field Detail
numColumns
protected int numColumns
numRows
protected int numRows
Constructor Detail
Grid
public Grid()
Grid
public Grid(int rows, int columns)
Constructs a grid with the requested size.
Parameters
- rows
- the number of rows
- columns
- the number of columns
Method Detail
clearCell
public boolean clearCell(int row, int column)
Clears the given row and column. If it contains a Widget, it will be
removed from the table. If not, its contents will simply be cleared.
Parameters
- row
- the widget's column
- column
- the widget's column
Return Value
true if a widget was removed
createCell
Creates a new, empty cell.
getColumnCount
public int getColumnCount()
Gets the number of columns in this grid.
Return Value
the number of columns
prepareCell
protected abstract void prepareCell(int row, int column)
Subclasses must implement this method. It allows them to decide what to do
just before a cell is accessed. If the cell already exists, this method
must do nothing. Otherwise, a subclass must either ensure that the cell
exists or throw an
IndexOutOfBoundsException.
Parameters
- row
- the cell's row
- column
- the cell's column
resize
public void resize(int rows, int columns)
Resizes the grid
Parameters
- rows
- the number of rows
- columns
- the number of columns
resizeColumns
public void resizeColumns(int columns)
Resizes the grid to the specified number of columns
Parameters
- columns
- the number of columns
resizeRows
public void resizeRows(int rows)
Resizes the grid to the specified number of rows
Parameters
- rows
- the number of rows