This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating Values In Fields

 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you really need to post this in 3 forums?
 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad.
No one was replying. Wasn't sure where it should go.
I'm a newbie. Forgive me.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also some good open source validation frameworks out there that you can either use or take ideas from. For example, JGoodies Validation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic