Package 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:
HasAllDragAndDropHandlers,HasClickHandlers,HasDoubleClickHandlers,HasDragEndHandlers,HasDragEnterHandlers,HasDragHandlers,HasDragLeaveHandlers,HasDragOverHandlers,HasDragStartHandlers,HasDropHandlers,HasAttachHandlers,HasHandlers,EventListener,HasVisibility,HasWidgets,HasWidgets.ForIsWidget,IsWidget,SourcesTableEvents,Iterable<Widget>
- Direct Known Subclasses:
CellGridImpl
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);
}
}
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 styleName="optionalHeaderStyle">
<g:customCell styleName="optionalFooCellStyle">
<g:Label>foo</g:Label>
</g:customCell>
<g:customCell styleName="optionalBarCellStyle">
<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>
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.HTMLTable
HTMLTable.Cell, HTMLTable.CellFormatter, HTMLTable.ColumnFormatter, HTMLTable.RowFormatterNested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidget -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intNumber of columns in the current grid.protected intNumber of rows in the current grid.Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanclearCell(int row, int column) Replaces the contents of the specified cell with a single space.protected ElementCreates a new, empty cell.intgetCellCount(int row) Return number of columns.intGets the number of columns in this grid.intReturn number of rows.intinsertRow(int beforeRow) Inserts a new row into the table.protected voidprepareCell(int row, int column) Checks that a cell is a valid cell in the table.protected voidprepareColumn(int column) Checks that the column index is valid.protected voidprepareRow(int row) Checks that the row index is valid.voidremoveRow(int row) Removes the specified row from the table.voidresize(int rows, int columns) Resizes the grid.voidresizeColumns(int columns) Resizes the grid to the specified number of columns.voidresizeRows(int rows) Resizes the grid to the specified number of rows.Methods inherited from class com.google.gwt.user.client.ui.HTMLTable
addCells, addClickHandler, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addTableListener, checkCellBounds, checkRowBounds, clear, clear, getBodyElement, getCellForEvent, getCellFormatter, getCellPadding, getCellSpacing, getColumnFormatter, getDOMCellCount, getDOMCellCount, getDOMCellCount, getDOMRowCount, getDOMRowCount, getDOMRowCount, getEventTargetCell, getHTML, getRowFormatter, getText, getWidget, insertCell, insertCells, internalClearCell, internalClearCell, isCellPresent, iterator, onEnsureDebugId, remove, removeCell, removeTableListener, setBorderWidth, setCellFormatter, setCellPadding, setCellSpacing, setColumnFormatter, setHTML, setHTML, setRowFormatter, setText, setWidget, setWidgetMethods inherited from class com.google.gwt.user.client.ui.Panel
add, add, adopt, doAttachChildren, doDetachChildren, orphan, removeMethods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsMethods 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, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEventMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
numColumns
protected int numColumnsNumber of columns in the current grid. -
numRows
protected int numRowsNumber of rows in the current grid.
-
-
Constructor Details
-
Grid
public Grid()Constructor forGrid. -
Grid
public Grid(int rows, int columns) Constructs a grid with the requested size.- Parameters:
rows- the number of rowscolumns- the number of columns- Throws:
IndexOutOfBoundsException
-
-
Method Details
-
clearCell
public boolean clearCell(int row, int column) Replaces the contents of the specified cell with a single space.- Overrides:
clearCellin classHTMLTable- Parameters:
row- the cell's rowcolumn- the cell's column- Returns:
- true if a widget was removed
- Throws:
IndexOutOfBoundsException
-
getCellCount
public int getCellCount(int row) Return number of columns. For grid, row argument is ignored as all grids are rectangular.- Specified by:
getCellCountin classHTMLTable- 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:
getRowCountin classHTMLTable- 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, useresize(int, int)orresizeRows(int)as they are more efficient.- Overrides:
insertRowin classHTMLTable- Parameters:
beforeRow- the index before which the new row will be inserted- Returns:
- the index of the newly-created row
- Throws:
IndexOutOfBoundsException
-
removeRow
public void removeRow(int row) Description copied from class:HTMLTableRemoves the specified row from the table. -
resize
public void resize(int rows, int columns) Resizes the grid.- Parameters:
rows- the number of rowscolumns- the number of columns- Throws:
IndexOutOfBoundsException
-
resizeColumns
public void resizeColumns(int columns) Resizes the grid to the specified number of columns.- Parameters:
columns- the number of columns- Throws:
IndexOutOfBoundsException
-
resizeRows
public void resizeRows(int rows) Resizes the grid to the specified number of rows.- Parameters:
rows- the number of rows- Throws:
IndexOutOfBoundsException
-
createCell
Creates a new, empty cell.- Overrides:
createCellin classHTMLTable- 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:
prepareCellin classHTMLTable- Parameters:
row- the cell's rowcolumn- the cell's column- Throws:
IndexOutOfBoundsException
-
prepareColumn
protected void prepareColumn(int column) Checks that the column index is valid.- Overrides:
prepareColumnin classHTMLTable- Parameters:
column- The column index to be checked- Throws:
IndexOutOfBoundsException- if the column is negative
-
prepareRow
protected void prepareRow(int row) Checks that the row index is valid.- Specified by:
prepareRowin classHTMLTable- Parameters:
row- The row index to be checked- Throws:
IndexOutOfBoundsException- if the row is negative
-