# Class StickyHeaderContainer

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.components.StickyHeaderContainer

All Implemented Interfaces:
  `Animation, Editable, StyleListener, Iterable<Component>`

public class StickyHeaderContainer extends Container

A scrollable container that pins the most recently scrolled-past section header to the top of its viewport, in the style of the iOS contacts list or sectioned material lists. As the user scrolls past a section boundary the previous header is replaced by the next one through a configurable staged transition: a directional slide (slides up on forward scroll, down on reverse scroll) or a cross-fade. Transitions are time-driven so a slow scroll surfaces every animation frame at full duration while a fast scroll lets the latest swap supersede earlier in-flight ones.

Sections are added with `addSection(header, content)`. The header is a real component that participates in the scroll: when it is the active section's header it is moved into a pinned overlay slot at the top of the container, and a same-sized invisible placeholder is left behind in the scroll content so nothing jumps. Because the pinned header is the same instance, action listeners and child components remain interactive while it is pinned.

    StickyHeaderContainer sticky = new StickyHeaderContainer();
    sticky.setTransitionStyle(StickyHeaderContainer.TRANSITION_SLIDE);
    sticky.setTransitionDurationMillis(250);
    for (char c = 'A'; c <= 'Z'; c++) {
        Label header = new Label("" + c, "StickyHeader");
        Container items = new Container(BoxLayout.y());
        for (int i = 0; i < 5; i++) {
            items.add(new Label(c + " entry " + i));
        }
        sticky.addSection(header, items);
    }
    form.add(BorderLayout.CENTER, sticky);

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `TRANSITION_FADE`
  Fade the outgoing header to transparency on top of the incoming one.
  `static final int`
  `TRANSITION_NONE`
  Replace the pinned header without animation.
  `static final int`
  `TRANSITION_SLIDE`
  Slide the outgoing header out of the slot while the incoming header slides in.

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StickyHeaderContainer()`
  Creates an empty sticky header container.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `StickyHeaderContainer`
  `addSection(Component header)`
  Adds a header-only section.
  `StickyHeaderContainer`
  `addSection(Component header, Component content)`
  Adds a section consisting of a sticky header and its content.
  `boolean`
  `animate()`
  Allows the animation to reduce "repaint" calls when it returns false.
  `void`
  `clearSections()`
  Removes all sections and content from the container.
  `protected void`
  `deinitialize()`
  Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
  `int`
  `getActiveSectionIndex()`
  Returns the index of the currently pinned section, or `-1` if no header is currently pinned.
  `Container`
  `getScrollContainer()`
  Returns the inner scrolling container that hosts the section content.
  `int`
  `getScrollPosition()`
  Returns the current scroll position of the inner scroll container.
  `List<Component>`
  `getStickyHeaders()`
  Returns an unmodifiable view of the registered sticky headers in the order they were added.
  `Container`
  `getStickyHost()`
  Returns the overlay container that hosts the currently-pinned header.
  `int`
  `getTransitionDurationMillis()`
  `float`
  `getTransitionProgress()`
  Returns the progress of the in-flight transition as a fraction in `[0, 1]`.
  `int`
  `getTransitionStyle()`
  `boolean`
  `isTransitionInProgress()`
  Returns true while a header replacement animation is in progress.
  `void`
  `paint(Graphics g)`
  This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
  `protected void`
  `paintGlass(Graphics g)`
  This method can be overriden by a component to draw on top of itself or its children after the component or the children finished drawing in a similar way to the glass pane but more refined per component
  `void`
  `setScrollPosition(int y)`
  Sets the scroll position of the inner scroll container.
  `void`
  `setTransitionDurationMillis(int millis)`
  Sets the duration of the header replacement animation in milliseconds.
  `void`
  `setTransitionStyle(int style)`
  Selects how the pinned header is replaced when the active section changes.
  `void`
  `updateSticky()`
  Recomputes which section header should be pinned and updates the overlay accordingly.

  ### Methods inherited from class Container

  `add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paintComponentBackground, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices`

  ### Methods inherited from class Component

  `addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### TRANSITION_NONE

    public static final int TRANSITION_NONE
    Replace the pinned header without animation.
    See Also:
      - Constant Field Values

  - ### TRANSITION_SLIDE

    public static final int TRANSITION_SLIDE
    Slide the outgoing header out of the slot while the incoming header slides in. Forward scroll slides upward, reverse scroll slides downward.
    See Also:
      - Constant Field Values

  - ### TRANSITION_FADE

    public static final int TRANSITION_FADE
    Fade the outgoing header to transparency on top of the incoming one.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### StickyHeaderContainer

    public StickyHeaderContainer()
    Creates an empty sticky header container. Add sections via `addSection(header, content)`.

- ## Method Details

  - ### addSection

    public StickyHeaderContainer addSection(Component header, Component content)
    Adds a section consisting of a sticky header and its content. The content may be `null` for a header-only section. Returns this for chaining.

  - ### addSection

    public StickyHeaderContainer addSection(Component header)
    Adds a header-only section.

  - ### getScrollContainer

    public Container getScrollContainer()
    Returns the inner scrolling container that hosts the section content. Use this to add non-section components such as a footer, or for programmatic scrolling via `setScrollPosition(int)`.

  - ### getStickyHost

    public Container getStickyHost()
    Returns the overlay container that hosts the currently-pinned header. While a section is active its header lives here; otherwise the host is empty and zero-height.

  - ### getStickyHeaders

    public List<Component> getStickyHeaders()
    Returns an unmodifiable view of the registered sticky headers in the order they were added.

  - ### getActiveSectionIndex

    public int getActiveSectionIndex()
    Returns the index of the currently pinned section, or `-1` if no header is currently pinned.

  - ### setTransitionStyle

    public void setTransitionStyle(int style)
    Selects how the pinned header is replaced when the active section changes. One of `TRANSITION_NONE`, `TRANSITION_SLIDE` (default) or `TRANSITION_FADE`.

  - ### getTransitionStyle

    public int getTransitionStyle()

  - ### setTransitionDurationMillis

    public void setTransitionDurationMillis(int millis)
    Sets the duration of the header replacement animation in milliseconds. A value of `0` makes transitions instantaneous regardless of `getTransitionStyle()`.

  - ### getTransitionDurationMillis

    public int getTransitionDurationMillis()

  - ### isTransitionInProgress

    public boolean isTransitionInProgress()
    Returns true while a header replacement animation is in progress.

  - ### getTransitionProgress

    public float getTransitionProgress()
    Returns the progress of the in-flight transition as a fraction in `[0, 1]`. Returns `1` when no transition is running.

  - ### setScrollPosition

    public void setScrollPosition(int y)
    Sets the scroll position of the inner scroll container. The value is clamped to the valid range and triggers a sticky-header recompute.

  - ### getScrollPosition

    public int getScrollPosition()
    Returns the current scroll position of the inner scroll container.

  - ### clearSections

    public void clearSections()
    Removes all sections and content from the container.

  - ### updateSticky

    public void updateSticky()
    Recomputes which section header should be pinned and updates the overlay accordingly. The container calls this internally on scroll; call it explicitly when section content has been mutated outside of a normal layout cycle.

  - ### animate

    public boolean animate()
    Description copied from class: `Component`

    Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the `com.codename1.ui.Display` class.

    ###### Returns

    true if a repaint is desired or false if no repaint is necessary

    Specified by:
      `animate` in interface `Animation`
    Overrides:
      `animate` in class `Component`

  - ### paint

    public void paint(Graphics g)
    Description copied from class: `Container`

    This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

    ###### Parameters

    - `g`: the component graphics
    Specified by:
      `paint` in interface `Animation`
    Overrides:
      `paint` in class `Container`

  - ### paintGlass

    protected void paintGlass(Graphics g)
    Description copied from class: `Container`

    This method can be overriden by a component to draw on top of itself or its children after the component or the children finished drawing in a similar way to the glass pane but more refined per component

    ###### Parameters

    - `g`: the graphics context
    Overrides:
      `paintGlass` in class `Container`

  - ### deinitialize

    protected void deinitialize()
    Description copied from class: `Component`
    Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
    Overrides:
      `deinitialize` in class `Component`