wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Validating Values In Fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Validating Values In Fields" Watch "Validating Values In Fields" New topic
Author

Validating Values In Fields

Dylan Margoczi
Ranch Hand

Joined: Jul 12, 2007
Posts: 38
Hey people.

I'm experiencing problems when validating values in fields
I currently validate whenever I loose focus on a field but the problem is that I display a message box each time the value is incorrect.
So when you go into a new field and the last field had an incorrect value it will loose focus from the new field when the message box pops up and so it validates that field as well.

I tried flagging it when focus is gained (and only then validating it), but it seems to gain focus on the next field before it displays the message box and so reseting the flag.

thanks Dylan.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
did you really need to post this in 3 forums?
Dylan Margoczi
Ranch Hand

Joined: Jul 12, 2007
Posts: 38
My bad.
No one was replying. Wasn't sure where it should go.
I'm a newbie. Forgive me.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
validating/error message scenario in focusLost is generally a bad idea.

InputVerifier() is a much better solution, and perhaps a JFormattedTextField or
DocumentFilter even better. Depends on whether you want an error message displayed, or
instead, just have the textfield not accept erroneous input
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
There are also some good open source validation frameworks out there that you can either use or take ideas from. For example, JGoodies Validation
 
wood burning stoves
 
subject: Validating Values In Fields
 
Similar Threads
Validating values in fields
Validating Values in fields
generating textfields when i click a button
Focus problem wiht Mac OS
Validating values in fields