Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which button of JSpinner has been pressed?

Tags:

java

swing

Is it possible to know , from inside a ChangeListener receiving a ChangeEvent from a JSpinner, which button (increment/decrement) has been pressed?

like image 623
Heisenbug Avatar asked Mar 03 '11 18:03

Heisenbug


2 Answers

Short answer : No there's no way to know which button was pressed

Long answer : depending on your model and your change listener, if you do a comparison between the new value and the previous value, it is possible to know if the user went forward or backward.

like image 162
krtek Avatar answered Oct 18 '22 11:10

krtek


You can inspect the object firing the event. Perhaps save the value prior to the event and determine whether it went up or down during the event.

like image 24
Morten Kristensen Avatar answered Oct 18 '22 09:10

Morten Kristensen