Java Reference
In-Depth Information
Slider
is similar to
ScrollBar
, but
Slider
has more properties and can appear in
many forms.
Key
Point
Figure 16.24 shows two sliders.
Slider
lets the user graphically select a value by sliding
a knob within a bounded interval. The slider can show both major tick marks and minor
tick marks between them. The number of pixels between the tick marks is specified by the
majorTickUnit
and
minorTickUnit
properties. Sliders can be displayed horizontally or
vertically, with or without ticks, and with or without labels.
VideoNote
Use
Slider
Vertical slider
Text
Horizontal slider
F
IGURE
16.24
The sliders move the message on a pane horizontally and vertically.
The frequently used constructors and properties in
Slider
are shown in Figure 16.25.
The getter and setter methods for property
values and a getter for property itself are provided
in the class, but omitted in the UML diagram for brevity.
javafx.scene.control.Slider
-blockIncrement: DoubleProperty
-max: DoubleProperty
-min: DoubleProperty
-value: DoubleProperty
-orientation: ObjectProperty<Orientation>
-majorTickUnit: DoubleProperty
-minorTickCount: IntegerProperty
-showTickLabels: BooleanProperty
-showTickMarks: BooleanProperty
The amount to adjust the slider if the track of the bar is clicked (default:
10
).
The maximum value represented by this slider (default:
100
).
The minimum value represented by this slider (default:
0
).
Current value of the slider (default:
0
).
Specifies the orientation of the slider (default:
HORIZONTAL
).
The unit distance between major tick marks.
The number of minor ticks to place between two major ticks.
Specifies whether the labels for tick marks are shown.
Specifies whether the tick marks are shown.
+Slider()
+Slider(min: double, max: double,
value: double)
Creates a default horizontal slider.
Creates a slider with the specified min, max, and value.
F
IGURE
16.25
Slider
enables the user to select from a range of values.
Note
The values of a vertical scroll bar increase from top to bottom, but the values of a vertical
slider decrease from top to bottom.
You can add a listener to listen for the
value
property change in a slider in the same way
as in a scroll bar. We now rewrite the program in the preceding section using the sliders to
move a text displayed on a pane in Listing 16.11. A sample run of the program is shown in
Figure 16.24.
Search WWH ::
Custom Search