How to limit the number of characters in a JTextField in Java? [closed]

0

I would like to limit the number of characters that are entered in a JTextField in java

    
asked by Manuel Nava 19.04.2017 в 05:02
source

1 answer

4

You have to use KeyListener

    public void keyTyped(KeyEvent e) 

    {
if (jTextFieldName.getText().length()== limite) 

         e.consume(); 
    } 

limit is the maximum number of characters you want.

e.consume()  

removes the characters that are entered when the limit is reached.

    
answered by 19.04.2017 / 05:18
source