Class Tr<T extends Tr<T>>


public class Tr<T extends Tr<T>> extends StyledElement<T>
Represents the HTML <tr> element for defining a table row.

The Tr class provides a Java representation of the HTML table row element, which defines a horizontal row of cells within a table. Each row can contain header cells (<th>) or data cells (<td>), and provides convenient methods for cell creation and management.

Features:

  • Header cell (th) creation and management
  • Data cell (td) creation and management
  • Multiple overloaded methods for cell creation with various parameters
  • Cell width and style configuration
  • Support for text, HTML elements, or styled cells
  • Bulk cell creation capability
  • Cell retrieval and counting methods
  • Automatic parent table update propagation

Usage Example:


 // Create a header row
 Tr headerRow = new Tr();
 headerRow.addHeaderCell("Product");
 headerRow.addHeaderCell("Price", 100);
 headerRow.addHeaderCell("Quantity", "text-center");

 // Create a data row with various cell types
 Tr dataRow = new Tr();
 dataRow.addDataCell("Widget");
 dataRow.addDataCell("$19.99");

 // Create a cell with an element
 TextInput quantityInput = new TextInput();
 dataRow.addDataCell(quantityInput);

 // Create multiple cells at once
 Tr emptyRow = new Tr();
 TableCells cells = emptyRow.addDataCells(5);

 // Access cells
 TableCell firstCell = dataRow.getCell(0);
 TableCells allCells = dataRow.getCells();
 int cellCount = dataRow.getNumberOfCells();
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Tr

      public Tr()
      Creates a new table row element.
  • Method Details

    • addCell

      public final void addCell(TableCell cell)
      Adds an existing table cell to this row.
      Parameters:
      cell - the TableCell to add
    • addHeaderCell

      public final Th addHeaderCell()
      Creates and adds an empty header cell to this row.
      Returns:
      the newly created Th element
    • addHeaderCell

      public final Th addHeaderCell(CssStyle style)
      Creates and adds a header cell with the specified style.
      Parameters:
      style - the CssStyle to apply to the cell
      Returns:
      the newly created Th element
    • addHeaderCell

      public final Th addHeaderCell(Element element)
      Creates a header cell containing the specified element.
      Parameters:
      element - the Element to place in the cell
      Returns:
      the Th element (either the input if it's a Th, or a new Th containing it)
    • addHeaderCell

      public final Th addHeaderCell(Element element, int width)
      Creates a header cell containing the specified element with a fixed width.
      Parameters:
      element - the Element to place in the cell
      width - the cell width in pixels
      Returns:
      the Th element
    • addHeaderCell

      public final Th addHeaderCell(Element element, String style)
      Creates a header cell containing the specified element with a CSS class.
      Parameters:
      element - the Element to place in the cell
      style - the CSS class name to apply
      Returns:
      the Th element
    • addHeaderCell

      public final Th addHeaderCell(String text)
      Creates a header cell with the specified text content.
      Parameters:
      text - the text to display in the cell
      Returns:
      the newly created Th element
    • addHeaderCell

      public final Th addHeaderCell(String text, String style)
      Creates a header cell with text and a CSS class.
      Parameters:
      text - the text to display in the cell
      style - the CSS class name to apply
      Returns:
      the newly created Th element
    • addHeaderCell

      public final Th addHeaderCell(String text, int width)
      Creates a header cell with text and a fixed width.
      Parameters:
      text - the text to display in the cell
      width - the cell width in pixels
      Returns:
      the newly created Th element
    • addDataCell

      public final Td addDataCell()
      Creates and adds an empty data cell to this row.
      Returns:
      the newly created Td element
    • addDataCell

      public final Td addDataCell(CssStyle style)
      Creates and adds a data cell with the specified style.
      Parameters:
      style - the CssStyle to apply to the cell
      Returns:
      the newly created Td element
    • addDataCell

      public final Td addDataCell(Element element)
      Creates a data cell containing the specified element.
      Parameters:
      element - the Element to place in the cell
      Returns:
      the Td element (either the input if it's a Td, or a new Td containing it)
    • addDataCell

      public final Td addDataCell(Element element, int width)
      Creates a data cell containing the specified element with a fixed width.
      Parameters:
      element - the Element to place in the cell
      width - the cell width in pixels
      Returns:
      the Td element
    • addDataCell

      public final Td addDataCell(String text)
      Creates a data cell with the specified text content.
      Parameters:
      text - the text to display in the cell
      Returns:
      the newly created Td element
    • addDataCell

      public final Td addDataCell(String text, int width)
      Creates a data cell with text and a fixed width.
      Parameters:
      text - the text to display in the cell
      width - the cell width in pixels
      Returns:
      the newly created Td element
    • addDataCell

      public final Td addDataCell(Element element, CssStyle style)
      Creates a data cell containing the specified element with a CssStyle.
      Parameters:
      element - the Element to place in the cell
      style - the CssStyle to apply to the cell
      Returns:
      the Td element
    • addDataCell

      public final Td addDataCell(Element element, String style)
      Creates a data cell containing the specified element with a CSS class.
      Parameters:
      element - the Element to place in the cell
      style - the CSS class name to apply
      Returns:
      the Td element
    • addDataCell

      public final Td addDataCell(String text, CssStyle style)
      Creates a data cell with text and a CssStyle.
      Parameters:
      text - the text to display in the cell
      style - the CssStyle to apply to the cell
      Returns:
      the newly created Td element
    • addDataCell

      public final Td addDataCell(String text, String style)
      Creates a data cell with text and a CSS class.
      Parameters:
      text - the text to display in the cell
      style - the CSS class name to apply
      Returns:
      the newly created Td element
    • addDataCells

      public final TableCells addDataCells(int num)
      Creates multiple empty data cells.
      Parameters:
      num - the number of cells to create
      Returns:
      a TableCells collection containing the created cells
    • getCells

      public final TableCells getCells()
      Returns all cells in this row.
      Returns:
      a TableCells collection containing all cells
    • getHeaderCells

      public final TableCells getHeaderCells()
      Returns all header cells in this row.
      Returns:
      a TableCells collection containing only Th elements
    • getDataCells

      public final TableCells getDataCells()
      Returns all data cells in this row.
      Returns:
      a TableCells collection containing only Td elements
    • getCell

      public final TableCell getCell(int colnum)
      Returns the cell at the specified column index.
      Parameters:
      colnum - the zero-based column index
      Returns:
      the TableCell at the specified index, or null if not found
    • removeAllCells

      public final void removeAllCells()
      Removes all cells from this row.
    • getNumberOfCells

      public final int getNumberOfCells()
      Returns the number of cells in this row.
      Returns:
      the cell count
    • registerAddition

      public void registerAddition()
      Description copied from class: Element
      Registers this element for addition to the DOM.
      Overrides:
      registerAddition in class Element<T extends Tr<T>>
    • registerSubtraction

      public void registerSubtraction()
      Description copied from class: Element
      Registers this element for removal from the DOM.

      Notifies the page that this element should be removed from the client-side DOM during the next update cycle.

      Overrides:
      registerSubtraction in class Element<T extends Tr<T>>
    • registerUpdate

      public void registerUpdate()
      Description copied from class: Element
      Registers this element for update in the DOM.

      Notifies the page that this element has been modified and should be synchronized with the client-side DOM during the next update cycle.

      Overrides:
      registerUpdate in class Element<T extends Tr<T>>