Skip to content

ScrollerView

Since 2.2.1

ScrollerView is a scrollable container. It wraps a viewContainer inside a viewPort and provides optional horizontal and vertical scroll bars that appear automatically when content overflows. Children added to a ScrollerView in code or XML are placed inside viewContainer.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var sv = new ScrollerView();
sv.scrollerStyle(style -> style.mode(ScrollerMode.VERTICAL));
for (int i = 0; i < 20; i++) {
    sv.addScrollViewChild(new Label().setText("Item " + i, false));
}
parent.addChild(sv);

XML

xml
<scroller-view>
    <label>Item 1</label>
    <label>Item 2</label>
    <label>Item 3</label>
</scroller-view>

Direct XML children are placed inside viewContainer.


Internal Structure

CSS classDescription
.__scroller_view_vertical-container__Row flex container holding viewPort and the vertical scroller.
.__scroller_view_view-port__Clipping viewport with default 5 px padding and border texture.
.__scroller_view_view-container__The actual content container where children are placed.
.__scroller_view_vertical-scroller__Vertical scroll bar (right side).
.__scroller_view_horizontal-scroller__Horizontal scroll bar (bottom).

ScrollerView Style

INFO

scroller-view-mode

Which scroll axes are enabled. Values: HORIZONTAL, VERTICAL, BOTH.

Default: BOTH

java
sv.scrollerStyle(style -> style.mode(ScrollerMode.VERTICAL));

INFO

scroller-vertical-display / scroller-horizontal-display

Visibility policy for each scroll bar. Values: AUTO (show only when content overflows), ALWAYS, NEVER.

Default: AUTO

java
sv.scrollerStyle(style -> style
    .verticalScrollDisplay(ScrollDisplay.ALWAYS)
    .horizontalScrollDisplay(ScrollDisplay.NEVER)
);

INFO

scroller-view-margin

Right margin reserved for the horizontal scroller when the vertical scroller is also visible.

Default: 5

css
scroller-view {
    scroller-view-margin: 5;
}

INFO

adaptive-width / adaptive-height

When enabled, the ScrollerView resizes itself to match the content container's computed width or height.

Default: false

java
sv.scrollerStyle(style -> style.adaptiveHeight(true));

INFO

min-scroll / max-scroll

Clamp bounds (in pixels) on how far the scroll bar thumb travels per scroll event.

Defaults: 5 / 7

java
sv.scrollerStyle(style -> style.minScrollPixel(0f).maxScrollPixel(20f));

Fields

NameTypeAccessDescription
viewContainerUIElementpublic finalContainer holding all added children.
viewPortUIElementpublic finalClipping region (has border texture and padding).
verticalContainerUIElementpublic finalRow flex container wrapping viewPort and verticalScroller.
horizontalScrollerScroller.Horizontalpublic finalHorizontal scroll bar.
verticalScrollerScroller.Verticalpublic finalVertical scroll bar.

Methods

MethodReturnsDescription
addScrollViewChild(UIElement)ScrollerViewAdds a child to viewContainer.
addScrollViewChildAt(UIElement, int)ScrollerViewInserts a child at a specific index in viewContainer.
addScrollViewChildren(UIElement...)ScrollerViewAdds multiple children to viewContainer.
removeScrollViewChild(UIElement)booleanRemoves a child from viewContainer.
clearAllScrollViewChildren()voidRemoves all children from viewContainer.
hasScrollViewChild(UIElement)booleanReturns true if the element is a child of viewContainer.
getContainerWidth()floatComputed content width (includes overflowing children).
getContainerHeight()floatComputed content height (includes overflowing children).
scrollerStyle(Consumer&lt;ScrollerViewStyle&gt;)ScrollerViewConfigures the style fluently.
viewContainer(Consumer&lt;UIElement&gt;)ScrollerViewConfigures viewContainer.
viewPort(Consumer&lt;UIElement&gt;)ScrollerViewConfigures viewPort.
verticalContainer(Consumer&lt;UIElement&gt;)ScrollerViewConfigures verticalContainer.
horizontalScroller(Consumer&lt;Scroller&gt;)ScrollerViewConfigures the horizontal scroll bar.
verticalScroller(Consumer&lt;Scroller&gt;)ScrollerViewConfigures the vertical scroll bar.

Released under the MIT License.