Skip to content
stefvanschie edited this page May 16, 2020 · 3 revisions

Languages: Dutch (Nederlands)

A slider is similar to a percentage bar in that it displays a part of a whole. The difference is that with a slider the user can manually change this value that is used. This is done by clicking on the slider to adjust it's percentage.

To create such a slider, you may invoke its constructor.

Slider slider = new Slider(0, 0, 9, 6);

You can then, if you wish to do so, change its default value by invoking setValue. Keep in mind that this value is specified as a floating point number in the range of (0,1).

slider.setValue(0.5F);

The orientation can also be changed from its default horizontal state, to a vertical state in which the slider goes from top to bottom.

slider.setOrientation(Orientable.Orientation.VERTICAL);

You can also flip the slider so it fills from right to left or, if the orientation is set to vertical, from bottom to top. This can be achieved by calling either flipHorizontally and/or flipVertically.

slider.flipHorizontally(true);
slider.flipVertically(true);

XML

Everything stated in Panes also applies here.

To create a slider you may use the slider element.

<slider x="0" y="0" length="9" height="6"/>

You can also specify a default value by setting the value attribute.

<slider x="0" y="0" length="9" height="6" value="0.5"/>

You can also specify the orientation with the orientation attribute.

<slider x="0" y="0" length="9" height="6" orientation="vertical"/>

And specify that it should flip by using the flipHorizontally and flipVertically attributes.

<slider x="0" y="0" length="9" height="6" flipHorizontally="true"/>
<slider x="0" y="0" length="9" height="6" flipVertically="true"/>
Clone this wiki locally