Slider
A JSlider: the user picks a whole number between min and max by dragging a knob along a track. A value the user leaves the knob on and the caller does not answer with a matching value is settled back onto the declared one once the drag is released, so the knob ends where the composition says.
A drag is published a value at a time: the slider passes through every value between the one it was grabbed at and the one it is let go on, and each of them reaches onValueChange as the user reaches it, while onValueSettled hears the value the drag was released on and none of the ones it passed through. A caller that follows the drag adopts onValueChange; a caller that acts on the released value alone - one that starts work too expensive to run per step - takes onValueSettled and leaves value where it is until then, and the slider follows the mouse in the meantime.
Parameters
the current value
callback invoked with every value the user moves the slider to, the ones a drag passes through included, and with the value the slider is left on where it cannot hold value - one outside the range, or one off the grid snapToTicks resolves to; applying a value the slider can hold is not itself reported
the SwingModifier applied to the underlying component
callback invoked with the value the slider settles on: the one a drag is released on, one the user reaches outside a drag, and the value the slider is left on where it cannot hold value
the smallest value the slider can hold; 0 by default
the largest value the slider can hold; 100 by default
the orientation of the slider (an Orientation SwingConstants value); HORIZONTAL by default, which runs the track across the width the slider is given
whether the value axis runs backwards, with the maximum at the left or bottom end; false by default, which puts the minimum at that end instead
the value distance between major tick marks, 0 for none - the default
the value distance between minor tick marks, 0 for none - the default
whether the tick marks are painted; false by default, which draws a bare track
whether the value labels are painted; false by default, which draws no text along the track
the text to draw at each value, keyed by the value the label sits at. null leaves the labels to Swing, which draws one at every major tick mark when paintLabels is true and majorTickSpacing is positive
whether a value the user picks resolves to the closest tick mark; false by default, which lets the knob rest on any value in the range. The grid is minorTickSpacing where it is positive and majorTickSpacing otherwise, so with neither declared there is no grid to snap to
See also
A Slider driven by a raw ChangeListener instead of the onValueChange and onValueSettled lambdas. The changeListener is attached as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid a detach/re-attach on every recomposition. Being attached as-is, it is notified of every change to the slider's value - the values a drag passes through as well as the one it settles on, and the change that applies value included - and reads getValueIsAdjusting off the slider to tell them apart.
Parameters
the current value
the listener notified when the value changes
the SwingModifier applied to the underlying component
the smallest value the slider can hold; 0 by default
the largest value the slider can hold; 100 by default
the orientation of the slider (an Orientation SwingConstants value); HORIZONTAL by default, which runs the track across the width the slider is given
whether the value axis runs backwards, with the maximum at the left or bottom end; false by default, which puts the minimum at that end instead
the value distance between major tick marks, 0 for none - the default
the value distance between minor tick marks, 0 for none - the default
whether the tick marks are painted; false by default, which draws a bare track
whether the value labels are painted; false by default, which draws no text along the track
the text to draw at each value, keyed by the value the label sits at. null leaves the labels to Swing, which draws one at every major tick mark when paintLabels is true and majorTickSpacing is positive
whether a value the user picks resolves to the closest tick mark; false by default, which lets the knob rest on any value in the range. The grid is minorTickSpacing where it is positive and majorTickSpacing otherwise, so with neither declared there is no grid to snap to
See also
A Slider over a caller-owned BoundedRangeModel. The model owns the value and the range, so nothing is declared over it: the slider renders whatever the model holds, the library never writes to it, and a model the caller mutates repaints the slider without a recomposition. Supplying a new model instance installs it on recomposition.
This is what lets one range drive several widgets - a slider and the ProgressBar reading it out, or two views of the same position - since each of them renders the model as-is:
val range = remember { DefaultBoundedRangeModel(30, 0, 0, 100) }
Slider(model = range)
ProgressBar(model = range)A drag reaches onValueChange a value at a time and onValueSettled once, on the value it is released on; see the declared-value Slider for what each channel carries.
Parameters
the range the slider renders and the user moves; owned by the caller and never written to by the library
the SwingModifier applied to the underlying component
callback invoked with every value the slider publishes, the ones a drag passes through included
callback invoked with the value the slider settles on: the one a drag is released on, and one the value reaches outside a drag
the orientation of the slider (an Orientation SwingConstants value); HORIZONTAL by default, which runs the track across the width the slider is given
whether the value axis runs backwards, with the maximum at the left or bottom end; false by default, which puts the minimum at that end instead
the value distance between major tick marks, 0 for none - the default
the value distance between minor tick marks, 0 for none - the default
whether the tick marks are painted; false by default, which draws a bare track
whether the value labels are painted; false by default, which draws no text along the track
the text to draw at each value, keyed by the value the label sits at. null leaves the labels to Swing, which draws one at every major tick mark when paintLabels is true and majorTickSpacing is positive
whether a value the user picks resolves to the closest tick mark; false by default, which lets the knob rest on any value in the range. The grid is minorTickSpacing where it is positive and majorTickSpacing otherwise, so with neither declared there is no grid to snap to
See also
A model-driven Slider driven by a raw ChangeListener instead of the onValueChange and onValueSettled lambdas. The model is rendered as-is and never written to by the library. The changeListener is attached as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid churn, and read getValueIsAdjusting off the slider to tell the values a drag passes through from the one it settles on.
Parameters
the range the slider renders and the user moves; owned by the caller and never written to by the library
the listener notified when the value changes
the SwingModifier applied to the underlying component
the orientation of the slider (an Orientation SwingConstants value); HORIZONTAL by default, which runs the track across the width the slider is given
whether the value axis runs backwards, with the maximum at the left or bottom end; false by default, which puts the minimum at that end instead
the value distance between major tick marks, 0 for none - the default
the value distance between minor tick marks, 0 for none - the default
whether the tick marks are painted; false by default, which draws a bare track
whether the value labels are painted; false by default, which draws no text along the track
the text to draw at each value, keyed by the value the label sits at. null leaves the labels to Swing, which draws one at every major tick mark when paintLabels is true and majorTickSpacing is positive
whether a value the user picks resolves to the closest tick mark; false by default, which lets the knob rest on any value in the range. The grid is minorTickSpacing where it is positive and majorTickSpacing otherwise, so with neither declared there is no grid to snap to