aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using InputVerifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using InputVerifier" Watch "Using InputVerifier" New topic
Author

Using InputVerifier

Isaac Shabtay
Greenhorn

Joined: Oct 31, 2004
Posts: 10
Hey all,

anybody here used an InputVerifier when verifying input in a dialog?

Seems like a neat idea, but how would you overcome this?

1) User enters inappropriate data in a JTextField which has an InputVerifier associated with it.

2) User decides that he had enough of URLyBird for today and hits "Cancel".

3) Hitting "Cancel" causes Swing to attempt transferring the focus to the "Cancel" button, thus trying to validate the input field.

4) Validation of the input field fails, so focus stays on the JTextField.

Conclusion: User cannot exit the dialog.


Enlighten my way, please.


"Large Vehicles Require More Room" - Highway 69 en route to Sudbury, Ontario
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello Isaac
Why are you validating JTextField text when the cancel button is pressed?
I think verifying the data when the user press the ok button, not when the JTextField lose the focus is an easier path.
Regards
[ December 14, 2004: Message edited by: Ignacio del Valle ]

SCJP, OCMJD, OCMJEA
Isaac Shabtay
Greenhorn

Joined: Oct 31, 2004
Posts: 10
Originally posted by Ignacio del Valle:
Hello Isaac
Why are you validating JTextField text when the cancel button is pressed?
I think verifying the data when the user press the ok button, not when the JTextField lose the focus is an easier path.
Regards

[ December 14, 2004: Message edited by: Ignacio del Valle ]


I know it is an easier path. And that is the way I am currently implementing it. I was just considering to switch to using InputVerifier's, because, naturally, this is what SUN has provided for input validation. And this is the way that input validators work: They validate the data when the component loses focus.
 
jQuery in Action, 2nd edition
 
subject: Using InputVerifier