I have 2 jtextfield and I want to validate the number of characters they type in them
text_root_username = new JTextField();
text_root_username.addKeyListener(this);//////
text_root_password = new JPasswordField();
text_root_password.addKeyListener(this);
I accept them with the following method
@Override
public void keyTyped(KeyEvent e) {
if(text_root_password.getText().length()>=8){
e.consume();
}
if(text_root_username.getText().length()>=8) {
e.consume();
}
}
but what happens is that when you get to 8 characters does not let you write some other character in the other jtext and viseversa