Class FlexTable

public class FlexTable
extends HTMLTable
A flexible table that creates cells on demand. It can be jagged (that is, each row can contain a different number of cells) and individual cells can be set to span multiple rows or columns.

Example

public class FlexTableExample implements EntryPoint {

  public void onModuleLoad() {
    // Tables have no explicit size -- they resize automatically on demand.
    FlexTable t = new FlexTable();

    // Put some text at the table's extremes.  This forces the table to be
    // 3 by 3.
    t.setText(0, 0, "upper-left corner");
    t.setText(2, 2, "bottom-right corner");

    // Let's put a button in the middle...
    t.setWidget(1, 0, new Button("Wide Button"));

    // ...and set it's column span so that it takes up the whole row.
    t.getFlexCellFormatter().setColSpan(1, 0, 3);

    RootPanel.get().add(t);
  }
}

Nested Classes

FlexTable.FlexCellFormatterFlexTable-specific implementation of CellFormatter.

Constructors

FlexTable()

Methods

addCell(int)Appends a cell to the specified row.
getCellCount(int)Gets the number of cells on a given row.
getFlexCellFormatter()Explicitly gets the FlexCellFormatter.
insertCell(int, int)Inserts a new cell into the specified row.
insertRow(int)Inserts a new row into the table.
prepareCell(int, int)Subclasses must implement this method.
removeCell(int, int)Removes the specified cell from the table.
removeCells(int, int, int)Removes a number of cells from a row in the table.
removeRow(int)Removes the specified row from the table.

Constructor Detail

FlexTable

public FlexTable()

Method Detail

addCell

public void addCell(int row)
Appends a cell to the specified row.

Parameters

row
the row to which the new cell will be added

getCellCount

public int getCellCount(int row)
Gets the number of cells on a given row.

Parameters

row
the row whose cells are to be counted

Return Value

the number of cells present

getFlexCellFormatter

public FlexTable.FlexCellFormatter getFlexCellFormatter()
Explicitly gets the FlexCellFormatter. The results of HTMLTable.getCellFormatter() may also be downcast to a FlexCellFormatter.

Return Value

the FlexTable's cell formatter

insertCell

protected void insertCell(int row, int column)
Inserts a new cell into the specified row.

Parameters

row
the row into which the new cell will be inserted
column
the column before which the cell will be inserted

insertRow

protected int insertRow(int beforeRow)
Inserts a new row into the table.

Parameters

beforeRow
the index before which the new row will be inserted

Return Value

the index of the newly-created row

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

removeCell

protected void removeCell(int row, int column)
Removes the specified cell from the table.

Parameters

row
the row of the cell to remove
column
the column of cell to remove

removeCells

public void removeCells(int row, int column, int num)
Removes a number of cells from a row in the table.

Parameters

row
the row of the cells to be removed
column
the column of the first cell to be removed
num
the number of cells to be removed

removeRow

protected void removeRow(int row)
Removes the specified row from the table.

Parameters

row
the index of the row to be removed