Slider

The slider component serves both as a slider widget and as a progress indicator. The slider component can be displayed both in portrait and landscape orientations.

The slider widget allows users to select a value on a bounded interval via touch or keypad input. The current value can be displayed on top of the slider bar. The value can also be displayed as a percentage value. The following code creates and initialises a Slider for selecting values between 0-100 and displaying the selected value as a percentage on top.

Slider slider = new Slider();
slider.setEditable(true);
slider.setRenderValueOnTop(true);

Figure: Slider component

The progress indicator is used to visually display the user the current status of progress during a long-running task. If the progress status cannot be calculated, the progress indicator can be used in indefinite mode. In indefinite mode a continuous animation is displayed to indicate the user that something is happening. The following code creates and initialises an indefinite progress indicator:

Slider slider = new Slider();
slider.setEditable(false);
slider.setInfinite(true);

Figure: Indefinite progress indicator

To set the slider value programmatically, use the setSliderValue(int value) method. You can also use setProgress(int percentageValue). This method takes the relative slider value in range of 0 to 100 as a parameter and updates the slider accordingly.