Reputation: 596
I my app I have many of jTextFields. How can I validate all of JtextField?
I try something like this:
if((jTextField1.getText.length()<3) || (jTextField2.getText.length()<3) ||(jTextField1.getText.length()<3) ......){
........
}
What is a best way to validate text fields ?
Upvotes: 0
Views: 734
Reputation: 9429
You can do that in a callback, like when 'losing focus' event is fired:
jTextField1.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
JTextField f = (JTextField)e.getSource();
if((f.getText.length()<3) || (f.getText.length()<3) ||(f.getText.length()<3) ......){
// ........
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
Upvotes: 0
Reputation: 347334
List
of some kind and loop over themInputVerify
to perform post validation of the field, see Validating Input for more detailsDocumentFilters
to do real-time validation, see Implementing a Document Filter and DocumentFilter Examples for more detailsUpvotes: 3