Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Table

  1. Object
  2. 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.MergeA rectangular range of cells shown as one, anchored at its top-left cell.

Fields

public final String idThe block id.
public final int headerRowsThe number of leading rows repeated at the top of every page the table spans.
public final List<Table.Merge> mergesThe merged ranges, never overlapping.

Constructors

public Table(String id, List<List<List<Block>>> cells, List<Table.Merge> merges, int headerRows)Creates a table.

Methods

public List<Float> columnWidths()The preferred column widths in points, one per column, or an empty list when the columns share the width equally.
public Table withColumnWidths(float... points)A copy with preferred column widths.
public String id()The block id.
public int rows()The number of rows.
public int columns()The number of columns.
public List<Block> cell(int row, int column)The blocks of one cell.
public String cellText(int row, int column)The text of one cell without formatting, paragraphs joined by newlines.
public Table.Merge span(int row, int column)The merge anchored at a cell.
public boolean covered(int row, int column)Whether a cell is hidden inside a merge anchored elsewhere.
public Table withCell(int row, int column, List<Block> blocks)A copy with one cell’s blocks replaced.
public Table withMerges(List<Table.Merge> value)A copy with different merges.
public Table withHeaderRows(int value)A copy with a different number of header rows.
public Table insertRow(int at)A copy with a row of empty cells inserted.
public Table deleteRow(int at)A copy without one row.
public Table insertColumn(int at)A copy with a column of empty cells inserted.
public Table deleteColumn(int at)A copy without one column.
public static Table ofText(String id, String[][] values)Creates a table whose cells each hold one paragraph of plain text.
public boolean equals(Object o)Two tables are equal when their id, cells, merges, header rows and column widths are.
public int hashCode()A hash consistent with equals.

Inherited methods

Field details

id

public final String id
The block id.

headerRows

public final int headerRows
The number of leading rows repeated at the top of every page the table spans.

merges

public final List<Table.Merge> merges
The 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

id String
the block id
cells List<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.
merges List<Table.Merge>
merged ranges, or null for none
headerRows int
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

points float...
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

row int
the row
column int
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

row int
the row
column int
the column

Returns

the characters

span

public Table.Merge span(int row, int column)
The merge anchored at a cell.

Parameters

row int
the row
column int
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

row int
the row
column int
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

row int
the row
column int
the column
blocks List<Block>
the new contents

Returns

the copy

withMerges

public Table withMerges(List<Table.Merge> value)
A copy with different merges.

Parameters

value List<Table.Merge>
the merges

Returns

the copy

withHeaderRows

public Table withHeaderRows(int value)
A copy with a different number of header rows.

Parameters

value int
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

at int
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

at int
the row to delete

Returns

the copy

insertColumn

public Table insertColumn(int at)
A copy with a column of empty cells inserted.

Parameters

at int
the new column’s index, 0 to columns()

Returns

the copy

deleteColumn

public Table deleteColumn(int at)
A copy without one column.

Parameters

at int
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

id String
the table id
values String[][]
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

o Object
the other object

Returns

true when equal

hashCode

public int hashCode()
A hash consistent with equals.

Returns

the hash