Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trap up/down arrowbutton event in JSpinner  RSS feed

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends, sir, madam

I need to check whether the value entered in JSpinner is valid or not on click of up/down arrow button. So I need to trap the up/down arrow button click events.

Steps to be followed
1. User entered value in the JSpinner manually without using the up/down arrow keys.
2. If the user presses up/down key then I need to validate whether the value entered in JSpinner is valid or not. If not then I need to display some default value.

Is this possible ? Am I on the right track ?

Any help is highly appreciated.

Thanks and Regards
Rohit.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set your own ui, extending BasicSpinnerUI
override createNextButton() and createPreviousButton()
add actionListeners to both buttons
in actionPerformed, get the textfield and setValue(spinner.getValue())

if valid, no changes
if invalid, previous valid value will be set
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!