SplitPane

@Composable
fun SplitPane(modifier: SwingModifier = SwingModifier, orientation: Int = JSplitPane.HORIZONTAL_SPLIT, dividerLocation: Int = -1, onDividerLocationChange: (Int) -> Unit = {}, resizeWeight: Double = 0.0, oneTouchExpandable: Boolean? = null, dividerSize: Int? = null, continuousLayout: Boolean? = null, content: @Composable SplitPaneScope.() -> Unit)

Two sides of one area, split by a divider the user drags to give one side room at the other's expense

  • a JSplitPane. The pane holds the divider offset and reports the moves the user makes.

The pane holds its children on two sides of its own, first and second, rather than among indexed children, so every child names the side it occupies on its own modifier, through SplitPaneScope:

SplitPane(orientation = JSplitPane.HORIZONTAL_SPLIT) {
Navigator(modifier = SwingModifier.first())
Editor(modifier = SwingModifier.second())
}

A side hosts one child: dropping a child (e.g. behind an if) empties the side it occupied, a side no child names stays empty, and a child that names no side at all is refused.

Pass an offset as dividerLocation to place the divider; onDividerLocationChange fires with the new offset when the user moves it. An offset is applied when it changes and is not asserted again, so a divider the user has dragged stays where they left it. The default -1 is JSplitPane's own initial divider location, asking the pane to derive the position from the sides' preferred sizes (shaped by resizeWeight); the pane keeps that request as its divider location until it is realized on screen, at which point it resolves the position itself - that resolution is the look and feel settling the request, not a move, and is not reported.

Parameters

modifier

the SwingModifier applied to the underlying JSplitPane

orientation

the axis along which the two sides are arranged; the default HORIZONTAL_SPLIT puts them side by side, with the divider running top to bottom

dividerLocation

the divider offset in pixels (controlled), a value the look and feel reads; a negative offset - the default -1 is JSplitPane's own initial divider location - resets the divider to honor the sides' preferred sizes

onDividerLocationChange

callback invoked with the new offset when the user moves the divider; an offset the declaration itself applies is not reported, nor is the position a negative request resolves to once the pane is realized on screen

resizeWeight

how extra space is shared when the pane resizes, from 0.0 (all to the second side) to 1.0 (all to the first side); the default 0.0 leaves the first side the size it has, and a weight outside 0.0..1.0 is refused

oneTouchExpandable

whether the divider carries a widget that collapses either side in one click; null leaves the choice to the installed look and feel, withdrawing a declared choice hands it back, and a look and feel that does not support one-touch expanding ignores it

dividerSize

the divider thickness in pixels; null leaves the size to the installed look and feel, and withdrawing a declared size hands it back

continuousLayout

whether the two sides are laid out continuously as the divider is dragged rather than once it is released, where the drag draws an outline of where the divider is heading; null leaves the choice to the installed look and feel, and withdrawing a declared choice hands it back

content

the composable content of the pane; see SplitPaneScope

See also


@Composable
fun SplitPane(dividerLocationListener: PropertyChangeListener, modifier: SwingModifier = SwingModifier, orientation: Int = JSplitPane.HORIZONTAL_SPLIT, dividerLocation: Int = -1, resizeWeight: Double = 0.0, oneTouchExpandable: Boolean? = null, dividerSize: Int? = null, continuousLayout: Boolean? = null, content: @Composable SplitPaneScope.() -> Unit)

A SplitPane driven by a raw PropertyChangeListener instead of an onDividerLocationChange lambda. The listener is attached for the dividerLocation property as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid churn. Attached as-is, it hears every dividerLocation change the pane publishes, including the pane's own writes and, for a negative (default) dividerLocation, the position that request resolves to once realized on screen - old=-1 new=<resolved> - indistinguishable from a user's move.

Parameters

dividerLocationListener

the listener notified when the dividerLocation property changes

modifier

the SwingModifier applied to the underlying JSplitPane

orientation

the axis along which the two sides are arranged; the default HORIZONTAL_SPLIT puts them side by side, with the divider running top to bottom

dividerLocation

the divider offset in pixels (controlled), a value the look and feel reads; a negative offset - the default -1 is JSplitPane's own initial divider location - resets the divider to honor the sides' preferred sizes

resizeWeight

how extra space is shared when the pane resizes, from 0.0 (all to the second side) to 1.0 (all to the first side); the default 0.0 leaves the first side the size it has, and a weight outside 0.0..1.0 is refused

oneTouchExpandable

whether the divider carries a widget that collapses either side in one click; null leaves the choice to the installed look and feel, withdrawing a declared choice hands it back, and a look and feel that does not support one-touch expanding ignores it

dividerSize

the divider thickness in pixels; null leaves the size to the installed look and feel, and withdrawing a declared size hands it back

continuousLayout

whether the two sides are laid out continuously as the divider is dragged rather than once it is released, where the drag draws an outline of where the divider is heading; null leaves the choice to the installed look and feel, and withdrawing a declared choice hands it back

content

the composable content of the pane; see SplitPaneScope

See also