ScrollPane

@Composable
fun ScrollPane(modifier: SwingModifier = SwingModifier, state: ScrollState = rememberScrollState(), verticalScrollbar: Int = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, horizontalScrollbar: Int = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED, viewportBorder: Border? = null, wheelScrollingEnabled: Boolean = true, content: @Composable ScrollPaneScope.() -> Unit)

A scrolling view onto content larger than the room it has - a JScrollPane, with the viewport it scrolls and the headers and corners that stay put beside it declared as content.

The pane holds each of its children in one of its own regions - the viewport, the row header, the column header, and each of the four corners - rather than as an indexed child. So every child names the region it goes in, through ScrollPaneScope, and a child naming none is refused. Each region holds one view, so two children naming the same one are refused as well, and a child that goes away releases the region it held:

ScrollPane {
LongList(modifier = SwingModifier.viewport())
ColumnTitles(modifier = SwingModifier.columnHeader())
CornerBadge(modifier = SwingModifier.corner(JScrollPane.UPPER_TRAILING_CORNER))
}

Set a fixed viewport size with modifier = SwingModifier.preferredSize(...).

The scroll position is hoistable state, so the application can read it, drive it, and follow the user's scrolling:

val scroll = rememberScrollState()
Button(text = "To the bottom", onClick = { scroll.y = scroll.maxY })
ScrollPane(state = scroll) {
LongList(modifier = SwingModifier.viewport())
}

How far the pane scrolls per arrow button and per page, and whether the content is laid out at the viewport's own width or height, are the content's to declare - see ScrollPaneScope.viewport.

Parameters

modifier

the SwingModifier applied to the underlying JScrollPane

state

the pane's two-way scroll position; see ScrollState. Left out, the pane gets a state of its own, which nothing outside it reads or drives

verticalScrollbar

the vertical scrollbar policy; by default the bar is there only while the content is taller than the viewport

horizontalScrollbar

the horizontal scrollbar policy; by default the bar is there only while the content is wider than the viewport

viewportBorder

the border drawn around the viewport, inside the pane's own border and outside the scrolled content; null leaves the border to the installed look and feel, and withdrawing a declared border hands the look and feel's own back

wheelScrollingEnabled

whether the mouse wheel scrolls the pane; true by default

content

the composable content of the pane; see ScrollPaneScope

See also