Is it possible to disable a JSpinner down arrow button? How?

1.4k views Asked by At

I have a JSpinner which starts at 0 and when its value is 0, its down arrow button should be disabled so the value does not change. Does anyone knows how to disable a button in a JSpinner?

1

There are 1 answers

1
Howard On BEST ANSWER

You can use a SpinnerModel. E.g. the following line limits the values between 0 and MAX_VALUE (i.e. values are bounded by zero from below). Arguments are: value, min, max, step_size.

JSpinner jSpinner = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));

Note: the button is not disabled actually, but does not decrease the value.