Java Reference
In-Depth Information
Getting ready
The Slider control is part of the standard GUI controls offered by JavaFX in the
javafx.
scene.control
package. By sliding the slider along its track, users are both inputting data
by selecting the slider's position on the track, and they are getting visual feedback confirming
their input. If you have not used the JavaFX controls, it may be helpful to review the recipe
Creating a form with JavaFX controls
for some background information.
How to do it...
The following code snippet shows you how to use the Slider control as an input controller to
update the color values of another object on the stage. You can get the full code listing from
ch04/source-code/src/controls/SliderDemo.fx
.
var
rSlide
=
Slider
{
translateX:10 translateY:20 min:0 max:255 value:0
}
var
gSlide
=
Slider
{
translateX:10 translateY:40 min:0 max:255 value:0
}
var
bSlide
=
Slider
{
translateX:10 translateY:60 min:0 max:255 value:0
}
var circ = Circle {
fill :
bind
Color.rgb(
rSlide
.value,
gSlide
.value,
bSlide
.value
)
stroke:Color.WHITE strokeWidth:3 radius: 70
effect:DropShadow{offsetY:3 offsetX:3}
}
var
panel
= HBox{
width:w
spacing:20
nodeVPos:VPos.TOP
content:[
VBox {content: [
rSlide
,
gSlide
,
bSlide
]},
circ,
VBox{
spacing:20
content:[
Text{content: bind "R: {%.0f rSlide.value}"}
Text{content: bind "G: {%.0f gSlide.value}"}
Text{content: bind "B: {%.0f bSlide.value}"}
]
}
]
}



