Search code examples
javawidgetswtspinnercyclic

How to get a Spinner with non cyclic behaviour? (stop on max value)


I have a Spinner, which behaviour is cyclic by default:

Spinner spinner = new Spinner(composite, SWT.WRAP | SWT.BORDER);
spinner.setMaximum(5);

The objective is that when the user press the next button on 5, the 5 must not change to 0, and when the user is on 0 and press the previous button, the 0 must not change to 5.

Is it possible to change this?


Solution

  • The SWT.WRAP style specifies that the value wraps from the maximum to the minimum, so just leave out that style:

    Spinner spinner = new Spinner(composite, SWT.BORDER);
    spinner.setMaximum(5);