• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Validating Values In Fields

 
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.
 
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
 
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic