Search code examples
javafxjavafx-8spinner

Is there any way to make JavaFX spinner repeat its value range when hitting the lowest/highest value?


Is there any way to make JavaFX spinner repeat its value range when hitting the lowest/highest value? For example, here I have Spinner with minValue 1, maxValue 5, initial value 3:

Spinner spinner = new Spinner(1, 5, 3);

What I need is that when I reach number 1 and press down arrow, number 5 shows up and when I press up arrow, number 1 shows up.

I was wondering about checking when are the arrows pressed and edit the value if needed, but I think there might be some property or some other, simpler way, which does this automatically, but couldn't find any.

Thank You very much.


Solution

  • So, I think it is a good idea to sum this up and post the exact answer I needed.

    To create JavaFX Spinner with wrap-around values, I had to do this:

    SpinnerValueFactory<Integer> valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 5, 3);
    valueFactory.setWrapAround(true);
    Spinner<Integer> spinner = new Spinner<>();
    spinner.setValueFactory(valueFactory);