Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client.ui
Class Grid

    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

All Implemented Interfaces:
  HasClickHandlers, HasHandlers, EventListener, HasWidgets, SourcesTableEvents, java.lang.Iterable<Widget>

    public class Grid

extends HTMLTable

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);
>       }
>     }

Nested Class Summary

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.HTMLTable
`HTMLTable.Cell, HTMLTable.CellFormatter, HTMLTable.ColumnFormatter, HTMLTable.RowFormatter`

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
`UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled`

Field Summary
`protected int` | `numColumns` Number of columns in the current grid.
`protected int` | `numRows` Number of rows in the current grid.

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Constructor Summary
`Grid()` Constructor for `Grid`.
`Grid(int rows, int columns)` Constructs a grid with the requested size.

Method Summary
`boolean` | `clearCell(int row, int column)` Replaces the contents of the specified cell with a single space.
`protected Element` | `createCell()` Creates a new, empty cell.
`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.
`protected void` | `prepareCell(int row, int column)` Checks that a cell is a valid cell in the table.
`protected void` | `prepareColumn(int column)` Checks that the column index is valid.
`protected void` | `prepareRow(int row)` Checks that the row index is valid.
`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.

Methods inherited from class com.google.gwt.user.client.ui.HTMLTable
`addClickHandler, addTableListener, checkCellBounds, checkRowBounds, clear, getBodyElement, getCellForEvent, getCellFormatter, getCellPadding, getCellSpacing, getColumnFormatter, getDOMCellCount, getDOMCellCount, getDOMRowCount, getDOMRowCount, getEventTargetCell, getHTML, getRowFormatter, getText, getWidget, insertCell, insertCells, internalClearCell, isCellPresent, iterator, onEnsureDebugId, remove, removeCell, removeTableListener, setBorderWidth, setCellFormatter, setCellPadding, setCellSpacing, setColumnFormatter, setHTML, setRowFormatter, setText, setWidget`

Methods inherited from class com.google.gwt.user.client.ui.Panel
`add, adopt, adopt, disown, doAttachChildren, doDetachChildren, onLoad, onUnload, orphan`

Methods inherited from class com.google.gwt.user.client.ui.Widget
`addDomHandler, addHandler, delegateEvent, fireEvent, getHandlerCount, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, sinkEvents`

Methods inherited from class com.google.gwt.user.client.ui.UIObject
`addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Field Detail

### numColumns

    protected int numColumns

  Number of columns in the current grid.

### numRows

    protected int numRows

  Number of rows in the current grid.

Constructor Detail

### Grid

    public Grid()

  Constructor for `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
  Throws:
    `java.lang.IndexOutOfBoundsException`

Method Detail

### clearCell

    public boolean clearCell(int row,
                             int column)

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

  Overrides:
    `clearCell` in class `HTMLTable`
  Parameters:
    `row` - the cell's row
    `column` - the cell's column
  Returns:
    true if a widget was removed
  Throws:
    `java.lang.IndexOutOfBoundsException`

### getCellCount

    public int getCellCount(int row)

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

  Specified by:
    `getCellCount` in class `HTMLTable`
  Parameters:
    `row` - the row whose cells are to be counted
  Returns:
    the number of cells present in the row

### getColumnCount

    public int getColumnCount()

  Gets the number of columns in this grid.

  Returns:
    the number of columns

### getRowCount

    public int getRowCount()

  Return number of rows.

  Specified by:
    `getRowCount` in class `HTMLTable`
  Returns:
    the table's row count

### insertRow

    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.

  Overrides:
    `insertRow` in class `HTMLTable`
  Parameters:
    `beforeRow` - the index before which the new row will be inserted
  Returns:
    the index of the newly-created row
  Throws:
    `java.lang.IndexOutOfBoundsException`

### removeRow

    public void removeRow(int row)

  Description copied from class: `HTMLTable`
  Removes the specified row from the table.

  Overrides:
    `removeRow` in class `HTMLTable`
  Parameters:
    `row` - the index of the row to be removed

### resize

    public void resize(int rows,
                       int columns)

  Resizes the grid.

  Parameters:
    `rows` - the number of rows
    `columns` - the number of columns
  Throws:
    `java.lang.IndexOutOfBoundsException`

### resizeColumns

    public void resizeColumns(int columns)

  Resizes the grid to the specified number of columns.

  Parameters:
    `columns` - the number of columns
  Throws:
    `java.lang.IndexOutOfBoundsException`

### resizeRows

    public void resizeRows(int rows)

  Resizes the grid to the specified number of rows.

  Parameters:
    `rows` - the number of rows
  Throws:
    `java.lang.IndexOutOfBoundsException`

### createCell

    protected Element createCell()

  Creates a new, empty cell.

  Overrides:
    `createCell` in class `HTMLTable`
  Returns:
    the newly created TD

### prepareCell

    protected void prepareCell(int row,
                               int column)

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

  Specified by:
    `prepareCell` in class `HTMLTable`
  Parameters:
    `row` - the cell's row
    `column` - the cell's column
  Throws:
    `java.lang.IndexOutOfBoundsException`

### prepareColumn

    protected void prepareColumn(int column)

  Checks that the column index is valid.

  Overrides:
    `prepareColumn` in class `HTMLTable`
  Parameters:
    `column` - The column index to be checked
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the column is negative

### prepareRow

    protected void prepareRow(int row)

  Checks that the row index is valid.

  Specified by:
    `prepareRow` in class `HTMLTable`
  Parameters:
    `row` - The row index to be checked
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the row is negative

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD