Search code examples
javaswingjspinner

Java JSpinner increase value with down arrow


I have a JSpinner that has all integers as model. I want it's value to increase with the down arrow and value to decrease with up arrow,which is the exact opposite of the default usage.

I have already done this using a variable that has the previous value and added a Change Listener. Whenever a value changes i compare it to the previous. If it's about to increase i instead decrease it and vice versa.

I wanted to know if there is another way of doing it. Like a listener who knows which arrow is pressed.


Solution

  • SpinnerNumberModel model = new SpinnerNumberModel(5, 1, 100, -1); // Note: -ve step