I am using a JSpinner
to adjust values on a graph, which has an undo function. I don't want to create an undo for each spinner button click event, but rather a single undo when the user has finished clicking the JSpinner
buttons and has moved the mouse away from the spinner control.
The normal JSpinner
mouseExited
is very flaky if the user moves the mouse pointer away too quickly (moving it slowly works if the mouse pointer is detected on the border between the spinner buttons and the JSpinner
border). Is it possible to detect mouseExited for the spinner buttons themselves? 'FocusLost' does not enable the undo button if it is the first undo until the user clicks elsewhere and they may assume that their changes cannot be undone if they don't.
Any alternative ways of doing this would be appreciated. Thanks in advance.
Maybe you can use a MouseListener
and handle mouseEntered
and mouseExited
.
What happens with the undo logic if the user uses the keyboard to increase/decrease the spinner value?
Maybe a better solution is to listen for a value change and then start a Timer
to fire in 1 or 2 seconds. When the Timer fires you do you processing. Every time the value changes you reset the Timer. These will you will group all changes made within you defined interval. This solution would also work whether the uses the mouse or the keyboard.