There are 2 ways to change a spinner's value, either by clicking the up or down button, or by pressing the up or down key. If I know spinner's value is changed, how do I know whether it is caused by button clicking or key pressing?
Asked
Active
Viewed 186 times
0
-
2*"If I know spinner's value is changed, how do I know whether it is caused by button clicking or key pressing?"* What does it matter? See [What is the XY problem?](http://meta.stackexchange.com/q/66377) – Andrew Thompson Sep 15 '14 at 14:00
1 Answers
1
Try to get the current event from the event queue.
if (EventQueue.getCurrentEvent() instanceof KeyEvent) {
// process key event
} else if (EventQueue.getCurrentEvent() instanceof MouseEvent) {
// process mouse event
}
The method returns an AWTEvent but in most cases it's either mouse or key event.

Sergiy Medvynskyy
- 11,160
- 1
- 32
- 48