Search code examples
javaspinnerjtextfield

StepSize in SpinnerNumberModel java


I creates a spinner with an Integer SpinnerNumberModel.

SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step);

Base on docs.oracle:

stepSize - the difference between elements of the sequence

What does this exactly mean ?


Solution

  • From the documentation:

    Changes the size of the value change computed by the getNextValue and getPreviousValue methods.

    It's just like having a for-loop like this:

    for (int i = min; i <= max; i += step)
    

    If min is zero and max is 10:

    With a step of 1, the sequence is

    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    

    With a step of 2, the sequence is

    0, 2, 4, 6, 8, 10