Creating a Slider

The Slider control represents a numeric value with its thumb, and enables the user to choose a numeric value by dragging its thumb. In Step 28 of the exercise you interacted with the Slider, shown in Figure 6-10, to control the value of the ProgressIndicator directly above it. The following snippet from Listing 6-12 contains the code that realizes the Slider-related portions of this behavior:

final Slider slider = new Slider(-1, model.maxRpm, 0);
slider.setPrefWidth(200);
slider.valueProperty().bindBidirectional(model.rpm);

The range of the Slider is set through its min and max properties, which in this case are –1 and the value of the maxRpm instance variable located in the StarterAppModel class. The min and max properties and the initial value are passed via the constructor. Also, the value property of the Slider is bidirectionally bound to the rpm property in the model, which is used for keeping the ProgressIndicator updated as you experienced in Step 26. The following code snippet from Listing 6-1 contains the relevant instance variables from our StarterAppModel class:

public double maxRpm = 8000.0;
public DoubleProperty rpm = new SimpleDoubleProperty(0);