Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Table
- Object
- Table
ImplementsBlock
An immutable table: a rectangular grid of cells, each holding its own blocks (paragraphs, pictures and nested tables), with optional merged ranges.
The grid is always rectangular. A merged range keeps its covered cells in the grid; they are simply not shown, so inserting or deleting a row never has to reshape the grid.
Nested types
class Table.Merge | A rectangular range of cells shown as one, anchored at its top-left cell. |
Fields
public final String id | The block id. |
public final int headerRows | The number of leading rows repeated at the top of every page the table spans. |
public final List<Table.Merge> merges | The merged ranges, never overlapping. |
Constructors
public Table(String id, List<List<List<Block>>> cells, List<Table.Merge> merges, int headerRows) | Creates a table. |
Methods
Inherited methods
Field details
id
public final String idThe block id.
headerRows
public final int headerRowsThe number of leading rows repeated at the top of every page the table spans.
merges
public final List<Table.Merge> mergesThe merged ranges, never overlapping.
Constructor details
Table
public Table(String id, List<List<List<Block>>> cells, List<Table.Merge> merges, int headerRows)Creates a table.
Parameters
idString- the block id
cellsList<List<List<Block>>>- the rows; every row must have the same number of cells and every cell is a list of blocks. The lists are copied.
mergesList<Table.Merge>- merged ranges, or null for none
headerRowsint- the number of header rows
Method details
columnWidths
public List<Float> columnWidths()The preferred column widths in points, one per column, or an empty list when the
columns share the width equally. A table wider or narrower than the space it is laid
out in keeps the proportions.
Returns
the widths, unmodifiable
withColumnWidths
public Table withColumnWidths(float... points)A copy with preferred column widths.
Parameters
pointsfloat...- one positive width per column, in points; null or empty for equal columns
Returns
the copy
id
public String id()The block id.
Returns
the id
rows
public int rows()The number of rows.
Returns
the row count
columns
public int columns()The number of columns.
Returns
the column count
cell
public List<Block> cell(int row, int column)The blocks of one cell.
Parameters
rowint- the row
columnint- the column
Returns
an unmodifiable list
cellText
public String cellText(int row, int column)The text of one cell without formatting, paragraphs joined by newlines.
Parameters
rowint- the row
columnint- the column
Returns
the characters
span
public Table.Merge span(int row, int column)The merge anchored at a cell.
Parameters
rowint- the row
columnint- the column
Returns
the merge, or null when none starts there
covered
public boolean covered(int row, int column)Whether a cell is hidden inside a merge anchored elsewhere.
Parameters
rowint- the row
columnint- the column
Returns
true when covered
withCell
public Table withCell(int row, int column, List<Block> blocks)A copy with one cell’s blocks replaced.
Parameters
rowint- the row
columnint- the column
blocksList<Block>- the new contents
Returns
the copy
withMerges
public Table withMerges(List<Table.Merge> value)A copy with different merges.
Parameters
valueList<Table.Merge>- the merges
Returns
the copy
withHeaderRows
public Table withHeaderRows(int value)A copy with a different number of header rows.
Parameters
valueint- the header row count
Returns
the copy
insertRow
public Table insertRow(int at)A copy with a row of empty cells inserted. Merges below move down; a merge the new row
passes through grows by one.
Parameters
atint- the new row’s index, 0 to
rows()
Returns
the copy
deleteRow
public Table deleteRow(int at)A copy without one row. Merges shrink or disappear with it.
Parameters
atint- the row to delete
Returns
the copy
insertColumn
public Table insertColumn(int at)A copy with a column of empty cells inserted.
Parameters
atint- the new column’s index, 0 to
columns()
Returns
the copy
deleteColumn
public Table deleteColumn(int at)A copy without one column.
Parameters
atint- the column to delete
Returns
the copy
ofText
public static Table ofText(String id, String[][] values)Creates a table whose cells each hold one paragraph of plain text. Paragraph ids are
derived from the table id.
Parameters
idString- the table id
valuesString[][]- the cell texts, row by row; short rows are padded
Returns
the table
equals
public boolean equals(Object o)Two tables are equal when their id, cells, merges, header rows and column widths are.
Parameters
oObject- the other object
Returns
true when equal
hashCode
public int hashCode()A hash consistent with
equals.Returns
the hash