Class Thead<T extends Thead<T>>


public class Thead<T extends Thead<T>> extends StyledElement<T>
Represents an HTML <thead> element for grouping table header rows.

This class provides functionality to create and manage table header sections within HTML tables. The thead element groups one or more <tr> elements that contain header information for the table columns, typically using <th> elements. This semantic grouping improves table structure, accessibility, and enables independent styling of header rows. Headers can remain visible when scrolling through long tables and are repeated at the top of each page when tables span multiple printed pages.

Features:

  • Groups table rows containing header content
  • Provides semantic structure to HTML tables
  • Enables independent styling of table header rows
  • Supports sticky/fixed positioning during scrolling
  • Prints at top of each page for multi-page tables
  • Improves accessibility and screen reader navigation
  • Extends TableElement for table-specific functionality

Usage:


 // Create a table with header section
 Table table = new Table();

 // Add header
 Thead thead = new Thead();
 Tr headerRow = new Tr();
 headerRow.addElement(new Th("Name"));
 headerRow.addElement(new Th("Email"));
 headerRow.addElement(new Th("Phone"));
 thead.addElement(headerRow);
 table.addElement(thead);

 // Add body
 Tbody tbody = new Tbody();
 // ... add data rows
 table.addElement(tbody);

 // Multi-row header
 Thead complexHeader = new Thead();
 Tr row1 = new Tr();
 row1.addElement(new Th("Personal Information"));
 row1.getLastElement().setColSpan(2);
 complexHeader.addElement(row1);

 Tr row2 = new Tr();
 row2.addElement(new Th("First Name"));
 row2.addElement(new Th("Last Name"));
 complexHeader.addElement(row2);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Thead

      public Thead()
      Constructs a Thead element.

      Creates a new <thead> element that can contain table rows representing header content for an HTML table.

  • Method Details

    • addRow

      public Tr addRow()
      Creates and adds a new row to this table section.
      Returns:
      The newly created Tr element.
    • addRow

      public void addRow(Tr row)
      Adds an existing row to this table section.
      Parameters:
      row - The Tr element to add.
    • getRow

      public Tr getRow(int index)
      Returns the row at the specified index.
      Parameters:
      index - The zero-based index of the row to retrieve.
      Returns:
      The Tr element at the specified index, or null if the index is out of bounds.
    • getRows

      public TableRows getRows()
      Returns all rows contained in this table section.
      Returns:
      A TableRows collection containing all Tr elements in this section.
    • removeAllRows

      public void removeAllRows()
      Removes all rows from this table section.
    • removeRow

      public void removeRow(int index)
      Removes the row at the specified index.
      Parameters:
      index - The zero-based index of the row to remove.
    • removeRows

      public void removeRows(int start, int end)
      Removes rows in the specified range (inclusive).
      Parameters:
      start - The zero-based index of the first row to remove.
      end - The zero-based index of the last row to remove.
    • registerAddition

      public final void registerAddition()
      Registers an addition to this element by notifying the parent.

      Table sections delegate update registration to their parent table element to ensure proper synchronization of table structure changes.

      Overrides:
      registerAddition in class Element<T extends com.oorian.html.elements.TableElement<T>>
    • registerSubtraction

      public final void registerSubtraction()
      Registers a subtraction from this element by notifying the parent.

      Table sections delegate update registration to their parent table element to ensure proper synchronization of table structure changes.

      Overrides:
      registerSubtraction in class Element<T extends com.oorian.html.elements.TableElement<T>>
    • registerUpdate

      public final void registerUpdate()
      Registers an update to this element by notifying the parent.

      Table sections delegate update registration to their parent table element to ensure proper synchronization of table structure changes.

      Overrides:
      registerUpdate in class Element<T extends com.oorian.html.elements.TableElement<T>>