Class TableCell<T extends TableCell<T>>

Direct Known Subclasses:
Td, Th

public abstract class TableCell<T extends TableCell<T>> extends StyledContainerElement<T>
Abstract base class for HTML table cell elements (<td> and <th>).

This class provides common functionality for all table cell types, including support for cell spanning (rowspan and colspan), header associations, and default styling to prevent content overflow. It extends

invalid reference
StyledElement
to provide comprehensive CSS styling capabilities while managing table-specific attributes and behavior.

Features:

  • Abstract base for <td> and <th> elements
  • Supports column spanning for cells that extend across multiple columns
  • Supports row spanning for cells that extend across multiple rows
  • Associates cells with header cells for accessibility
  • Default styling with hidden overflow and 100% height
  • Propagates updates to parent elements for dynamic table management

Usage:


 // Concrete implementations (Td, Th) extend this class
 Td cell = new Td("Cell content");

 // Set column span for cell spanning multiple columns
 cell.setColSpan(2);

 // Set row span for cell spanning multiple rows
 cell.setRowSpan(3);

 // Associate cell with header for accessibility
 cell.setHeaders("header1 header2");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • invalid reference
    StyledElement
  • Td
  • Th
  • Tr
  • Constructor Details

    • TableCell

      public TableCell(String tagName)
      Constructs a TableCell with the specified HTML tag name.

      Initializes the table cell with default styling: overflow is set to hidden and height is set to 100% to ensure proper cell rendering and prevent content from extending beyond cell boundaries.

      Parameters:
      tagName - the HTML tag name for this cell (typically "td" or "th")
  • Method Details

    • setColSpan

      public T setColSpan(int colspan)
      Sets the number of columns this cell should span.

      Specifies how many columns wide this cell should be. A value greater than 1 causes the cell to extend across multiple columns, useful for creating complex table layouts. The default value is 1 (single column).

      Parameters:
      colspan - the number of columns to span (must be 1 or greater)
    • setHeaders

      public T setHeaders(String headerId)
      Associates this cell with one or more header cells.

      Specifies a space-separated list of header cell IDs that provide context for this cell. This improves accessibility by establishing relationships between data cells and their corresponding headers, particularly useful in complex tables with multiple header levels.

      Parameters:
      headerId - space-separated list of header cell IDs
    • setRowSpan

      public T setRowSpan(int rowspan)
      Sets the number of rows this cell should span.

      Specifies how many rows tall this cell should be. A value greater than 1 causes the cell to extend across multiple rows, useful for creating complex table layouts. The default value is 1 (single row).

      Parameters:
      rowspan - the number of rows to span (must be 1 or greater)
      Returns:
      this element for method chaining
    • getRowSpan

      protected int getRowSpan()
      Returns the rowspan attribute value.

      The rowspan attribute specifies the number of rows a table cell should span. Used on <td> and <th> elements. The default value is 1.

      Returns:
      The row span, or 0 if not set.
    • registerAddition

      public final void registerAddition()
      Registers that a child element has been added to this cell.

      Propagates the addition notification to the parent element, ensuring that table updates are properly tracked throughout the element hierarchy. This is part of the dynamic update mechanism for table management.

      Overrides:
      registerAddition in class Element<T extends TableCell<T>>
    • registerSubtraction

      public final void registerSubtraction()
      Registers that a child element has been removed from this cell.

      Propagates the removal notification to the parent element, ensuring that table updates are properly tracked throughout the element hierarchy. This is part of the dynamic update mechanism for table management.

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

      public final void registerUpdate()
      Registers that this cell or its content has been modified.

      Propagates the update notification to the parent element, ensuring that table changes are properly tracked throughout the element hierarchy. This is part of the dynamic update mechanism for table management.

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