Question

I have a JSpinner wich 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?

Thanks

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top