Class TableRow

All Implemented Interfaces:
AttachNotifier, ClickNotifier<TableRow>, DetachNotifier, HasComponentsOfType<TableCell>, HasElement, HasEnabled, HasSize, HasStyle, Serializable

@NullMarked @Tag("tr") public class TableRow extends HtmlComponent implements HasComponentsOfType<TableCell>, ClickNotifier<TableRow>
Component representing a <tr> element ? a row of a Table.

A <tr> may only contain <td> and <th> cells, which is what HasComponentsOfType expresses: the standard add, remove, replace and bindChildren operations are all available, but only for TableCell, so anything else is rejected at compile time. What this class adds on top are the cell factories, which create a cell and attach it in one call. To put arbitrary content in a row, put it inside a cell.

Since:
25.3
See Also:
  • Constructor Details

    • TableRow

      public TableRow()
      Creates a new empty row.
    • TableRow

      public TableRow(Component... components)
      Creates a new row with the given content, following the rules of addCells(Component...).
      Parameters:
      components - the cells, or the content to wrap in cells.
    • TableRow

      public TableRow(List<? extends Component> components)
      List equivalent of TableRow(Component...).
      Parameters:
      components - the cells, or the content to wrap in cells.
  • Method Details

    • addCells

      public TableRow addCells(Component... components)
      Appends the given components to this row. A TableCell is added as-is; anything else is wrapped in a new TableDataCell, since a <tr> may only contain cells. This is the lenient counterpart of the inherited add(TableCell...), which takes cells only and rejects anything else at compile time.
      Parameters:
      components - the cells, or the content to wrap in cells.
      Returns:
      this row, for fluent chaining.
    • addCells

      public TableRow addCells(List<? extends Component> components)
      List equivalent of addCells(Component...).
      Parameters:
      components - the cells, or the content to wrap in cells.
      Returns:
      this row, for fluent chaining.
    • addDataCells

      public TableRow addDataCells(String... cellTexts)
      Appends a sequence of data cells (<td>) with the given text contents to this row.

      For example, addDataCells("4.87", "12,104") renders as:

      
       <td>4.87</td>
       <td>12,104</td>
       
      Parameters:
      cellTexts - the text content for each data cell.
      Returns:
      this row, for fluent chaining.
    • addDataCells

      public TableRow addDataCells(List<String> cellTexts)
      List equivalent of addDataCells(String...).
      Parameters:
      cellTexts - the text content for each data cell.
      Returns:
      this row, for fluent chaining.
    • addHeaderCells

      public TableRow addHeaderCells(String... cellTexts)
      Appends a sequence of header cells (<th>) with the given text contents to this row.

      For example, addHeaderCells("Mon", "Tue") renders as:

      
       <th>Mon</th>
       <th>Tue</th>
       
      Parameters:
      cellTexts - the text content for each header cell.
      Returns:
      this row, for fluent chaining.
    • addHeaderCells

      public TableRow addHeaderCells(List<String> cellTexts)
      List equivalent of addHeaderCells(String...).
      Parameters:
      cellTexts - the text content for each header cell.
      Returns:
      this row, for fluent chaining.
    • addColumnHeaderCells

      public TableRow addColumnHeaderCells(String... cellTexts)
      Appends a header cell for each of the given texts, each labelling the column it sits in with scope="col". This is the bulk form of addColumnHeaderCell(String) and the usual way to fill a row in a TableHead.

      For example, addColumnHeaderCells("Mon", "Tue") renders as:

      
       <th scope="col">Mon</th>
       <th scope="col">Tue</th>
       
      Parameters:
      cellTexts - the text content of the cells, one cell per entry.
      Returns:
      this row, for chaining.
    • addColumnHeaderCells

      public TableRow addColumnHeaderCells(List<String> cellTexts)
      Parameters:
      cellTexts - the text content of the cells, one cell per entry.
      Returns:
      this row, for chaining.
    • addHeaderCell

      public TableHeaderCell addHeaderCell()
      Appends a new empty header cell to this row.
      Returns:
      the new <th>.
    • addHeaderCell

      public TableHeaderCell addHeaderCell(String text)
      Appends a new header cell with the given text to this row. The cell carries no scope; use addRowHeaderCell(String) or addColumnHeaderCell(String) when the cell labels a row or a column.

      A span goes on the cell handed back, so row.addHeaderCell("Animals").setColspan(2) is a single statement.

      Parameters:
      text - the text content.
      Returns:
      the new <th>.
    • addHeaderCell

      public TableHeaderCell addHeaderCell(Signal<String> textSignal)
      Appends a new header cell whose text content follows the given signal.

      The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <th>.
    • addHeaderCell

      public TableHeaderCell addHeaderCell(Component... content)
      Appends a new header cell holding the given content to this row, for a header that is more than plain text.
      Parameters:
      content - the content of the cell.
      Returns:
      the new <th>.
    • insertHeaderCell

      public TableHeaderCell insertHeaderCell(int position)
      Inserts a new empty header cell at the given position.
      Parameters:
      position - the position to insert the cell at, between 0 and the number of cells in this row.
      Returns:
      the new <th>.
    • addRowHeaderCell

      public TableHeaderCell addRowHeaderCell(String text)
      Appends a header cell to this row that labels the row itself, with scope="row" set on the resulting <th>. This is a shortcut for the common pattern of using a leading <th> as a row label, which assistive technologies announce as the header for the data cells in the same row.

      For example, addRowHeaderCell("Breed") renders as:

      
       <th scope="row">Breed</th>
       

      There is no overload taking a span, because a span goes on the cell handed back ? row.addRowHeaderCell("Horse").setRowspan(2) ? and because it would be ambiguous which of the two spans an int meant. addRowGroupHeaderCell(String, int) and addColumnGroupHeaderCell(String, int) do take one: there the span is what makes the cell a group header rather than decoration on it.

      Parameters:
      text - the text content.
      Returns:
      the new <th> with scope="row".
    • addRowHeaderCell

      public TableHeaderCell addRowHeaderCell(Signal<String> textSignal)
      Appends a header cell labelling the row it leads, with scope="row" set on the resulting <th> and its text content following the given signal.

      The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <th> with scope="row".
    • addRowHeaderCell

      public TableHeaderCell addRowHeaderCell(Component... content)
      Appends a header cell holding the given content and labelling the row it leads, with scope="row" set on the resulting <th>. This is the content-taking form of addRowHeaderCell(String), for a label that is not plain text.

      For example, addRowHeaderCell(new Span("Breed")) renders as:

      
       <th scope="row"><span>Breed</span></th>
       
      Parameters:
      content - the content of the cell.
      Returns:
      the new <th> with scope="row".
    • addColumnHeaderCell

      public TableHeaderCell addColumnHeaderCell(String text)
      Appends a header cell labelling the column it sits in, with scope="col" set on the resulting <th>. This is the counterpart of addRowHeaderCell(String) and the usual shape of a cell in a TableHead.

      For example, addColumnHeaderCell("Name") renders as:

      
       <th scope="col">Name</th>
       

      A span goes on the cell handed back, as it does for addRowHeaderCell(String); a header that spans the columns it names is usually better expressed with addColumnGroupHeaderCell(String, int).

      Parameters:
      text - the text content.
      Returns:
      the new <th> with scope="col".
    • addColumnHeaderCell

      public TableHeaderCell addColumnHeaderCell(Signal<String> textSignal)
      Appends a header cell labelling the column it sits in, with scope="col" set on the resulting <th> and its text content following the given signal.

      The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <th> with scope="col".
    • addColumnHeaderCell

      public TableHeaderCell addColumnHeaderCell(Component... content)
      Appends a header cell holding the given content and labelling the column it sits in, with scope="col" set on the resulting <th>. This is the content-taking form of addColumnHeaderCell(String), for a label that is not plain text.

      For example, addColumnHeaderCell(new Span("Name")) renders as:

      
       <th scope="col"><span>Name</span></th>
       
      Parameters:
      content - the content of the cell.
      Returns:
      the new <th> with scope="col".
    • addRowGroupHeaderCell

      public TableHeaderCell addRowGroupHeaderCell(String text)
      Appends a header cell labelling the band of rows it heads, with scope="rowgroup" set on the resulting <th>. Use it for the cell that names a group of consecutive rows, such as "Terrestrial planets" in front of the four rows describing them, as opposed to addRowHeaderCell(String), which labels one row.

      For example, addRowGroupHeaderCell("Dwarf planets") renders as:

      
       <th scope="rowgroup">Dwarf planets</th>
       
      Parameters:
      text - the text content.
      Returns:
      the new <th> with scope="rowgroup".
    • addRowGroupHeaderCell

      public TableHeaderCell addRowGroupHeaderCell(Signal<String> textSignal)
      Appends a header cell labelling the band of rows it heads, with scope="rowgroup" set on the resulting <th> and its text content following the given signal. Set the span on the returned cell with TableCell.setRowspan(int).

      The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <th> with scope="rowgroup".
    • addRowGroupHeaderCell

      public TableHeaderCell addRowGroupHeaderCell(Component... content)
      Appends a header cell holding the given content and labelling the band of rows it heads, with scope="rowgroup" set on the resulting <th>. This is the content-taking form of addRowGroupHeaderCell(String); set the span on the returned cell with TableCell.setRowspan(int), since a varargs parameter has to come last and so cannot be combined with one in a single call.

      For example, addRowGroupHeaderCell(new Span("Gas giants")) renders as:

      
       <th scope="rowgroup"><span>Gas giants</span></th>
       
      Parameters:
      content - the content of the cell.
      Returns:
      the new <th> with scope="rowgroup".
    • addRowGroupHeaderCell

      public TableHeaderCell addRowGroupHeaderCell(String text, int rowspan)
      Appends a header cell labelling the band of rows it heads, with scope="rowgroup" and the given rowspan set on the resulting <th>, so that the cell reaches over the rows it names.

      For example, addRowGroupHeaderCell("Terrestrial planets", 4) renders as:

      
       <th scope="rowgroup" rowspan="4">Terrestrial planets</th>
       
      Parameters:
      text - the text content.
      rowspan - the number of rows the header covers, or 0 to cover the rest of the row group.
      Returns:
      the new <th> with scope="rowgroup".
      Throws:
      IllegalArgumentException - if rowspan is negative.
    • addColumnGroupHeaderCell

      public TableHeaderCell addColumnGroupHeaderCell(String text)
      Appends a header cell labelling the band of columns it heads, with scope="colgroup" set on the resulting <th>. This is the counterpart of addRowGroupHeaderCell(String), for a cell that names a group of consecutive columns rather than a single one.

      For example, addColumnGroupHeaderCell("Measurements") renders as:

      
       <th scope="colgroup">Measurements</th>
       
      Parameters:
      text - the text content.
      Returns:
      the new <th> with scope="colgroup".
    • addColumnGroupHeaderCell

      public TableHeaderCell addColumnGroupHeaderCell(Signal<String> textSignal)
      Appends a header cell labelling the band of columns it heads, with scope="colgroup" set on the resulting <th> and its text content following the given signal. Set the span on the returned cell with TableCell.setColspan(int).

      The cell follows the signal for as long as it is attached, so this is the factory to use for a header whose label is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <th> with scope="colgroup".
    • addColumnGroupHeaderCell

      public TableHeaderCell addColumnGroupHeaderCell(Component... content)
      Appends a header cell holding the given content and labelling the band of columns it heads, with scope="colgroup" set on the resulting <th>. This is the content-taking form of addColumnGroupHeaderCell(String); set the span on the returned cell with TableCell.setColspan(int), since a varargs parameter has to come last and so cannot be combined with one in a single call.

      For example, addColumnGroupHeaderCell(new Span("Measurements")) renders as:

      
       <th scope="colgroup"><span>Measurements</span></th>
       
      Parameters:
      content - the content of the cell.
      Returns:
      the new <th> with scope="colgroup".
    • addColumnGroupHeaderCell

      public TableHeaderCell addColumnGroupHeaderCell(String text, int colspan)
      Appends a header cell labelling the band of columns it heads, with scope="colgroup" and the given colspan set on the resulting <th>, so that the cell reaches over the columns it names.

      For example, addColumnGroupHeaderCell("Measurements", 3) renders as:

      
       <th scope="colgroup" colspan="3">Measurements</th>
       
      Parameters:
      text - the text content.
      colspan - the number of columns the header covers.
      Returns:
      the new <th> with scope="colgroup".
      Throws:
      IllegalArgumentException - if colspan is less than 1.
    • addDataCell

      public TableDataCell addDataCell()
      Appends a new empty data cell to this row.
      Returns:
      the new <td>.
    • addDataCell

      public TableDataCell addDataCell(String text)
      Appends a new data cell with the given text to this row.
      Parameters:
      text - the text content.
      Returns:
      the new <td>.
    • addDataCell

      public TableDataCell addDataCell(Signal<String> textSignal)
      Appends a new data cell whose text content follows the given signal.

      The cell follows the signal for as long as it is attached, so this is the factory to use for a value that is reactive rather than fixed.

      Parameters:
      textSignal - the signal to bind, not null
      Returns:
      the new <td>.
    • addDataCell

      public TableDataCell addDataCell(Component... content)
      Appends a new data cell holding the given content to this row, for a cell that is more than plain text.
      Parameters:
      content - the content of the cell.
      Returns:
      the new <td>.
    • insertDataCell

      public TableDataCell insertDataCell(int position)
      Inserts a new empty data cell at the given position.
      Parameters:
      position - the position to insert the cell at, between 0 and the number of cells in this row.
      Returns:
      the new <td>.
    • getHeaderCells

      public List<TableHeaderCell> getHeaderCells()
      Returns the header cells of this row, in document order.
      Returns:
      this row's <th> cells.
    • getDataCells

      public List<TableDataCell> getDataCells()
      Returns the data cells of this row, in document order.
      Returns:
      this row's <td> cells.
    • getCells

      public List<TableCell> getCells()
      Returns every cell of this row, in document order, both kinds combined. This is the typed counterpart of Component.getChildren(). For kind-specific lists use getHeaderCells() or getDataCells().
      Returns:
      this row's cells.