I am making a GUI
using JavaFx
and I need sliders that only allow integers
to ever be selected.
I know I can use snapToT
You can simply add a listener to the valueProperty of the Slider
and then you can either set the integer value of the new Number
value:
slider.valueProperty().addListener((obs, oldval, newVal) ->
slider.setValue(newVal.intValue()));
or alternatively you can use integer rounding using Math.round:
slider.valueProperty().addListener((obs, oldval, newVal) ->
slider.setValue(Math.round(newVal.doubleValue())));