Class Th<T extends Th<T>>


public class Th<T extends Th<T>> extends TableCell<T>
Represents the HTML <th> element for defining a table header cell.

The Th class provides a Java representation of the HTML table header cell element, which defines header information for table columns or rows. Header cells are typically rendered with bold text and centered alignment by default, and provide important semantic meaning for accessibility and table structure.

Features:

  • Header labeling for table columns and rows
  • Abbreviated text support for accessibility
  • Scope definition (column, row, colgroup, rowgroup)
  • Sort state indication for sortable columns
  • Semantic HTML for improved accessibility
  • Inherits cell styling and spanning capabilities from TableCell

Usage Example:


 // Create simple header cells
 Th nameHeader = new Th();
 nameHeader.addText("Customer Name");
 nameHeader.setScope(ThScope.COL);

 // Create a header with abbreviation
 Th emailHeader = new Th();
 emailHeader.addText("Email Address");
 emailHeader.setAbbr("Email");
 emailHeader.setScope(ThScope.COL);

 // Create a sortable header
 Th priceHeader = new Th();
 priceHeader.addText("Price");
 priceHeader.setScope(ThScope.COL);
 priceHeader.setSorted("ascending");

 // Add headers to a table
 Tr headerRow = new Tr();
 headerRow.addCell(nameHeader);
 headerRow.addCell(emailHeader);
 headerRow.addCell(priceHeader);
 table.getHeader().addRow(headerRow);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Th

      public Th()
      Creates a new Th table header cell.
  • Method Details

    • setAbbr

      public void setAbbr(String text)
      Sets the abbreviated text for the header cell, used by screen readers and other assistive technologies.
      Parameters:
      text - The abbreviated text.
    • setScope

      public T setScope(ThScope scope)
      Sets the scope of the header cell using the ThScope enum.
      Parameters:
      scope - The scope indicating which cells this header applies to.
      Returns:
      This element for method chaining.
    • setScope

      public T setScope(String scope)
      Sets the scope of the header cell using a string value.
      Parameters:
      scope - The scope as a string (e.g., "col", "row", "colgroup", "rowgroup").
      Returns:
      This element for method chaining.
    • setSorted

      public void setSorted(String sorted)
      Sets the sort direction indicator for the header cell.
      Parameters:
      sorted - The sort state (e.g., "ascending", "descending").