Class HPanel


public class HPanel extends StyledElement<HPanel>
A horizontal panel container that arranges elements in a single row with multiple cells.

This container class extends CPanel to provide a table-based horizontal layout where elements are distributed across multiple cells in a single row. Each cell can have configurable width, alignment, and content. Useful for creating horizontal layouts like toolbars, headers, or multi-column content areas.

Features:

  • Single-row, multi-cell horizontal layout
  • Configurable cell widths (fixed, percentage, or auto)
  • Cell-specific width constraints (min, max)
  • Vertical alignment control (default: middle)
  • Automatic spacing between cells
  • Dynamic cell addition and removal

Usage:

 HPanel panel = new HPanel(3);  // 3 cells
 panel.setCellWidth(0, 200);    // First cell 200px
 panel.setCellWidth(1, "auto"); // Second cell auto
 panel.setCellWidth(2, "30%");  // Third cell 30%
 panel.addElement(0, logo);
 panel.addElement(1, title);
 panel.addElement(2, toolbar);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • VPanel
  • CPanel
  • invalid reference
    HStack
  • Field Details

    • LAYOUT_FIXED

      public static final String LAYOUT_FIXED
      Fixed table layout mode - fixed width columns
      See Also:
    • LAYOUT_AUTO

      public static final String LAYOUT_AUTO
      Auto table layout mode - automatic column sizing
      See Also:
    • LAYOUT_INHERIT

      public static final String LAYOUT_INHERIT
      Inherited table layout mode - inherit from parent
      See Also:
  • Constructor Details

    • HPanel

      public HPanel()
      Creates a new horizontal panel with a single empty row.
    • HPanel

      public HPanel(int cells)
      Creates a new horizontal panel with the specified number of cells.
      Parameters:
      cells - The number of cells to create.
  • Method Details

    • setNumCells

      public final void setNumCells(int numCells)
      Sets the number of cells in the panel, removing any existing cells.
      Parameters:
      numCells - The number of cells to create.
    • setCellWidth

      public final void setCellWidth(int cellIndex, int width)
      Sets the width of a cell in pixels.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The width in pixels.
    • setCellWidth

      public final void setCellWidth(int cellIndex, String width)
      Sets the width of a cell using a CSS value.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The CSS width value (e.g., "100px", "50%", "auto").
    • setMinCellWidth

      public final void setMinCellWidth(int cellIndex, int width)
      Sets the minimum width of a cell in pixels.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The minimum width in pixels.
    • setMinCellWidth

      public final void setMinCellWidth(int cellIndex, String width)
      Sets the minimum width of a cell using a CSS value.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The CSS min-width value (e.g., "100px", "50%").
    • setMaxCellWidth

      public final void setMaxCellWidth(int cellIndex, int width)
      Sets the maximum width of a cell in pixels.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The maximum width in pixels.
    • setMaxCellWidth

      public final void setMaxCellWidth(int cellIndex, String width)
      Sets the maximum width of a cell using a CSS value.
      Parameters:
      cellIndex - The zero-based cell index.
      width - The CSS max-width value (e.g., "200px", "80%").
    • addCell

      public final int addCell()
      Adds a new cell to the panel.
      Returns:
      The index of the newly added cell.
    • addCell

      public final int addCell(int width)
      Adds a new cell with a fixed pixel width.
      Parameters:
      width - The cell width in pixels.
      Returns:
      The index of the newly added cell.
    • addCell

      public final int addCell(String width)
      Adds a new cell with a CSS width value.
      Parameters:
      width - The CSS width value (e.g., "100px", "25%", "auto").
      Returns:
      The index of the newly added cell.
    • addCells

      public void addCells(int numCells)
      Adds multiple cells to the panel.
      Parameters:
      numCells - The number of cells to add.
    • addElement

      public Td addElement(int cellIndex, Element element)
      Adds an element to the specified cell.
      Parameters:
      cellIndex - The zero-based cell index.
      element - The element to add.
      Returns:
      The cell containing the element.
    • removeAllElements

      public void removeAllElements()
      Description copied from class: Element
      Removes all child elements from this element.

      Each child is unlinked and registered for DOM removal if the element is attached to a page.

      Overrides:
      removeAllElements in class Element<HPanel>
    • removeAllElements

      public void removeAllElements(int cellIndex)
      Removes all elements from the specified cell.
      Parameters:
      cellIndex - The zero-based cell index.
    • setVerticalAlign

      public StyledElement setVerticalAlign(VerticalAlign align)
      Sets the default vertical alignment for all cells.
      Parameters:
      align - The VerticalAlign value.
      Returns:
      This element for method chaining.
    • setVerticalAlign

      public final void setVerticalAlign(int cellIndex, VerticalAlign align)
      Sets the vertical alignment for a specific cell.
      Parameters:
      cellIndex - The zero-based cell index.
      align - The VerticalAlign value.
    • getNumberOfCells

      public int getNumberOfCells()
      Returns the number of cells in the panel.
      Returns:
      The cell count.
    • getElement

      public Element getElement(int index)
      Description copied from class: Element
      Returns the child element at the specified index.
      Parameters:
      index - The zero-based index of the child.
      Returns:
      The child element, or null if index is out of bounds.
    • getElement

      public Element getElement(int cellIndex, int elementIndex)
      Returns an element from a specific cell at a specific index.
      Parameters:
      cellIndex - The zero-based cell index.
      elementIndex - The zero-based element index within the cell.
      Returns:
      The element, or null if not found.
    • getElements

      public Elements getElements(int cellIndex)
      Returns all elements from a specific cell.
      Parameters:
      cellIndex - The zero-based cell index.
      Returns:
      An Elements collection containing the cell's elements.
    • onCreated

      protected final void onCreated()
      Description copied from class: Element
      Hook method called after the element has been created.

      Override this method to perform actions after creation is complete.

      Overrides:
      onCreated in class Element<HPanel>
    • setSpacing

      public final void setSpacing(int spacing)
    • addElement

      public final HPanel addElement(Element element)
      Description copied from class: Element
      Adds a child element to this element.

      The child is removed from its previous parent if it has one, then added to this element's children. If this element is already attached to a page, the child is also attached and registered for DOM addition.

      Overrides:
      addElement in class Element<T extends com.oorian.html.containers.CPanel<T>>
      Parameters:
      element - The child element to add.
      Returns:
      this element for method chaining
    • insertElement

      public final HPanel insertElement(int index, Element element)
      Description copied from class: Element
      Inserts a child element at the specified index.

      The child is removed from its previous parent if it has one, then inserted at the specified index in this element's children.

      Overrides:
      insertElement in class Element<T extends com.oorian.html.containers.CPanel<T>>
      Parameters:
      index - The index at which to insert the child.
      element - The child element to insert.
      Returns:
      this element for method chaining
    • getSpacing

      public final int getSpacing()
    • setWrapCellText

      public final void setWrapCellText(int cellIndex, boolean flag)
    • prewrite

      protected final void prewrite()
      Description copied from class: Element
      Hook method called before the element is written to output.

      Override this method to perform any last-minute configuration before rendering.

      Overrides:
      prewrite in class Element<T extends com.oorian.html.containers.CPanel<T>>
    • getHtml

      public void getHtml(StringBuilder buffer)
      Description copied from class: StyledElement
      Generates the HTML representation of this element, including state-based styles and interactive cursor attributes.
      Overrides:
      getHtml in class StyledElement<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      buffer - The StringBuilder to append the HTML output to.
    • setElement

      protected HPanel setElement(Element element)
      Replaces the content of this panel with the specified element.
      Overrides:
      setElement in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      element - The element to set as the sole content.
      Returns:
      This element for method chaining.
    • hasElements

      public boolean hasElements()
      Description copied from class: Element
      Checks if this element has any child elements.
      Overrides:
      hasElements in class Element<T extends com.oorian.html.containers.Panel<T>>
      Returns:
      true if this element has children, false otherwise.
    • getElements

      public Elements getElements()
      Description copied from class: Element
      Returns the direct children of this element.
      Overrides:
      getElements in class Element<T extends com.oorian.html.containers.Panel<T>>
      Returns:
      A copy of the children collection.
    • addText

      public final void addText(String text)
      Adds a text node to this panel.
      Overrides:
      addText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to add.
    • addText

      public final void addText(String text, String style)
      Adds styled text to this panel using a CSS style string.
      Overrides:
      addText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to add.
      style - The inline CSS style string.
    • addText

      public final void addText(String text, CssStyle style)
      Adds styled text to this panel using a CssStyle object.
      Overrides:
      addText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to add.
      style - The CssStyle to apply to the text.
    • setText

      public final void setText(String text)
      Sets the text content of this panel, replacing any existing content.
      Overrides:
      setText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to set. If null or empty, a non-breaking space is used.
    • setText

      public final void setText(String text, String style)
      Sets styled text content of this panel using a CSS style string, replacing any existing content.
      Overrides:
      setText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to set. If null or empty, a non-breaking space is used.
      style - The inline CSS style string.
    • setText

      public final void setText(String text, Font font)
      Sets styled text content of this panel using a Font, replacing any existing content.
      Overrides:
      setText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to set. If null or empty, a non-breaking space is used.
      font - The Font to apply to the text.
    • setText

      public final void setText(String text, CssStyle style)
      Sets styled text content of this panel using a CssStyle object, replacing any existing content.
      Overrides:
      setText in class Element<T extends com.oorian.html.containers.Panel<T>>
      Parameters:
      text - The text to set. If null or empty, a non-breaking space is used.
      style - The CssStyle to apply to the text.
    • initialize

      protected final void initialize()
      Description copied from class: Element
      Hook method called during element initialization.

      Override this method to set up the element's structure by adding child elements. This is called before Element.create() and only once during the element's lifecycle.

      Overrides:
      initialize in class StyledElement<T extends com.oorian.html.containers.Panel<T>>