Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation

 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello does anyone know how can i validate a jtextfield in swing .Example i want to have only digits 5 digits and not empty.
I have read about Hibernate validator but i don't know how to use it any examples?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're not otherwise using Hibernate just use a DocumentFilter.
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:If you're not otherwise using Hibernate just use a DocumentFilter.

can you explain what you mean?I have seen DocumentFilter.
 
Tony Docherty
Bartender
Posts: 2941
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to force the user to enter exactly 5 digits then look at JFormattedTextField.
Alternatively you can set an input verifier to check what a user has entered and stop focus shifting to the next component if the input is invalid - see javax.swing.InputVerifier
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:If you want to force the user to enter exactly 5 digits then look at JFormattedTextField.
Alternatively you can set an input verifier to check what a user has entered and stop focus shifting to the next component if the input is invalid - see javax.swing.InputVerifier


Thanks i will try them
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, be sure to checkout the example from our SwingFAQ: example
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:Also, be sure to checkout the example from our SwingFAQ: example

Thanks you both very helpful.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic