ScrollPane
A scrolling view onto content larger than the room it has - a JScrollPane, with the viewport it scrolls, its scroll bars, and the headers and corners that stay put beside them declared as content.
The pane builds its viewport and both scroll bars itself; ScrollPaneScope.Viewport, ScrollPaneScope.VerticalScrollbar and ScrollPaneScope.HorizontalScrollbar configure them, and the content of Viewport is the view the pane scrolls. The row header, the column header and each of the four corners are regions a child fills by naming one through ScrollPaneScope. A child declaring none of these is refused, and so are two declarations of one part or one region:
ScrollPane {
Viewport { LongList() }
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) {
Viewport { LongList() }
}How far the pane scrolls per arrow button and per page is declared on the viewport - see ScrollPaneScope.Viewport.
Parameters
the SwingModifier applied to the underlying JScrollPane
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
the vertical scrollbar policy; by default the bar is there only while the content is taller than the viewport
the horizontal scrollbar policy; by default the bar is there only while the content is wider than the viewport
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
whether the mouse wheel scrolls the pane; true by default
the composable content of the pane; see ScrollPaneScope