I'm using a Slider
in my javaFX project and I have a Label
that updates when I move the slider.
I want the Label
to update whilst I'm dragging the Slider
and not only when the drag is dropped.
This is my code:
betSlider.valueChangingProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> source, Boolean oldValue, Boolean newValue) {
betLabel.textProperty().setValue(String.valueOf((int)betSlider.getValue()));
} });
Adding an alternative that seems simpler and easier to me:
Given a slider named slMySlider and a label named lblMySlider
And if you want to do completely in in FXML, you can do this:
If you have a slider in JavaFX 8, you could do this:
You just need to change the
valueChangingProperty()
tovalueProperty()
and TADA, it works as you want !A small sample is attached here :
Bind the label's textProperty to the slider's valueProperty.
A format conversion is required in the binding to make it work.
Either Itachi's valueProperty() ChangeListener or a binding will work.