public class

Grid

extends HTMLTable
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Panel
         ↳ com.google.gwt.user.client.ui.HTMLTable
           ↳ com.google.gwt.user.client.ui.Grid

Class Overview

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

{@example com.google.gwt.examples.GridExample}

Use in UiBinder Templates

Grid widget consists of <g:row> elements. Each <g:row> element can contain one or more <g:cell> or <g:customCell> elements. Using <g:cell> attribute it is possible to place pure HTML content. <g:customCell> is used as a container for Widget type objects. (Note that the tags of the row, cell and customCell elements are not capitalized. This is meant to signal that the item is not a runtime object, and so cannot have a ui:field attribute.)

For example:

 <g:Grid>
  <g:row>
    <g:customCell>
      <g:Label>foo</g:Label>
    </g:customCell>
    <g:customCell>
      <g:Label>bar</g:Label>
    </g:customCell>
  </g:row>
  <g:row>
    <g:cell>
      <div>foo</div>
    </g:cell>
    <g:cell>
      <div>bar</div>
    </g:cell>
  </g:row>
 </g:Grid>
 

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Fields
protected int numColumns Number of columns in the current grid.
protected int numRows Number of rows in the current grid.
Public Constructors
Grid()
Constructor for Grid.
Grid(int rows, int columns)
Constructs a grid with the requested size.
Public Methods
boolean clearCell(int row, int column)
Replaces the contents of the specified cell with a single space.
int getCellCount(int row)
Return number of columns.
int getColumnCount()
Gets the number of columns in this grid.
int getRowCount()
Return number of rows.
int insertRow(int beforeRow)
Inserts a new row into the table.
void removeRow(int row)
Removes the specified row from the table.
void resize(int rows, int columns)
Resizes the grid.
void resizeColumns(int columns)
Resizes the grid to the specified number of columns.
void resizeRows(int rows)
Resizes the grid to the specified number of rows.
Protected Methods
Element createCell()
Creates a new, empty cell.
void prepareCell(int row, int column)
Checks that a cell is a valid cell in the table.
void prepareColumn(int column)
Checks that the column index is valid.
void prepareRow(int row)
Checks that the row index is valid.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.HTMLTable
From class com.google.gwt.user.client.ui.Panel
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.HasWidgets.ForIsWidget
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesTableEvents
From interface java.lang.Iterable

Fields

protected int numColumns

Number of columns in the current grid.

protected int numRows

Number of rows in the current grid.

Public Constructors

public Grid ()

Constructor for 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

Public Methods

public boolean clearCell (int row, int column)

Replaces the contents of the specified cell with a single space.

Parameters
row the cell's row
column the cell's column
Returns
  • true if a widget was removed

public int getCellCount (int row)

Return number of columns. For grid, row argument is ignored as all grids are rectangular.

Parameters
row the row whose cells are to be counted
Returns
  • the number of cells present in the row

public int getColumnCount ()

Gets the number of columns in this grid.

Returns
  • the number of columns

public int getRowCount ()

Return number of rows.

Returns
  • the table's row count

public int insertRow (int beforeRow)

Inserts a new row into the table. If you want to add multiple rows at once, use resize(int, int) or resizeRows(int) as they are more efficient.

Parameters
beforeRow the index before which the new row will be inserted
Returns
  • the index of the newly-created row

public void removeRow (int row)

Removes the specified row from the table.

Parameters
row the index of the row to be removed

public void resize (int rows, int columns)

Resizes the grid.

Parameters
rows the number of rows
columns the number of columns

public void resizeColumns (int columns)

Resizes the grid to the specified number of columns.

Parameters
columns the number of columns

public void resizeRows (int rows)

Resizes the grid to the specified number of rows.

Parameters
rows the number of rows

Protected Methods

protected Element createCell ()

Creates a new, empty cell.

Returns
  • the newly created TD

protected void prepareCell (int row, int column)

Checks that a cell is a valid cell in the table.

Parameters
row the cell's row
column the cell's column

protected void prepareColumn (int column)

Checks that the column index is valid.

Parameters
column The column index to be checked
Throws
IndexOutOfBoundsException if the column is negative

protected void prepareRow (int row)

Checks that the row index is valid.

Parameters
row The row index to be checked
Throws
IndexOutOfBoundsException if the row is negative