Class AccordionItem

All Implemented Interfaces:
ClientEventListener, MouseClickListener, EventListener

public class AccordionItem extends StyledElement<AccordionItem> implements MouseClickListener
An individual expandable/collapsible panel within an Accordion.

AccordionItem consists of two parts:

  • Header - Clickable area that triggers expand/collapse
  • Content - The expandable content area

Usage:


 // Create an accordion item
 AccordionItem item = new AccordionItem();
 item.setHeader(new H3("Section Title"));
 item.setContent(sectionContent);

 // Or use fluent factory
 AccordionItem item = AccordionItem.create("Section Title", content);

 // Add to accordion
 accordion.addItem(item);
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • AccordionItem

      public AccordionItem()
      Constructs an empty AccordionItem.
  • Method Details

    • initialize

      protected void initialize()
      Adds the header and content elements to the DOM tree.
      Overrides:
      initialize in class StyledElement<AccordionItem>
    • create

      public static AccordionItem create(String headerText, Element<?> contentElement)
      Creates an AccordionItem with the specified header text and content.
      Parameters:
      headerText - the header text
      contentElement - the content element
      Returns:
      a new AccordionItem
    • setHeader

      public AccordionItem setHeader(Element<?> headerElement)
      Sets the header element.
      Parameters:
      headerElement - the header element
      Returns:
      this AccordionItem for method chaining
    • setHeaderText

      public AccordionItem setHeaderText(String text)
      Sets the header text.
      Parameters:
      text - the header text
      Returns:
      this AccordionItem for method chaining
    • setContent

      public AccordionItem setContent(Element<?> contentElement)
      Sets the content element.
      Parameters:
      contentElement - the content element
      Returns:
      this AccordionItem for method chaining
    • expand

      public void expand()
      Expands this item to show its content.
    • collapse

      public void collapse()
      Collapses this item to hide its content.
    • toggle

      public void toggle()
      Toggles the expanded/collapsed state.
    • onEvent

      public void onEvent(MouseClickedEvent event)
      Handles click events on the header to toggle expand/collapse.
      Specified by:
      onEvent in interface MouseClickListener
      Parameters:
      event - the mouse click event
    • isExpanded

      public boolean isExpanded()
      Checks if this item is currently expanded.
      Returns:
      true if expanded, false if collapsed
    • setExpanded

      public AccordionItem setExpanded(boolean expanded)
      Sets whether this item starts expanded.
      Parameters:
      expanded - true to start expanded
      Returns:
      this AccordionItem for method chaining
    • getHeader

      public Div getHeader()
      Returns the header element for customization.
      Returns:
      the header div
    • getContent

      public Div getContent()
      Returns the content element for customization.
      Returns:
      the content div
    • setHeaderPadding

      public AccordionItem setHeaderPadding(int padding)
      Sets padding for the header.
      Parameters:
      padding - the padding in pixels
      Returns:
      this AccordionItem for method chaining
    • setHeaderPadding

      public AccordionItem setHeaderPadding(String padding)
      Sets padding for the header.
      Parameters:
      padding - the padding value (e.g., "1rem", "16px")
      Returns:
      this AccordionItem for method chaining
    • setContentPadding

      public AccordionItem setContentPadding(int padding)
      Sets padding for the content area.
      Parameters:
      padding - the padding in pixels
      Returns:
      this AccordionItem for method chaining
    • setContentPadding

      public AccordionItem setContentPadding(String padding)
      Sets padding for the content area.
      Parameters:
      padding - the padding value (e.g., "1rem", "16px")
      Returns:
      this AccordionItem for method chaining
    • setHeaderBackground

      public AccordionItem setHeaderBackground(String color)
      Sets the header background color.
      Parameters:
      color - the background color
      Returns:
      this AccordionItem for method chaining
    • setContentBackground

      public AccordionItem setContentBackground(String color)
      Sets the content background color.
      Parameters:
      color - the background color
      Returns:
      this AccordionItem for method chaining
    • setBorder

      public AccordionItem setBorder(String border)
      Adds a bottom border to the item.
      Overrides:
      setBorder in class StyledElement<AccordionItem>
      Parameters:
      border - the border value (e.g., "1px solid #ddd")
      Returns:
      this AccordionItem for method chaining