Limiting TextField inputs

前端 未结 2 853
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-07 04:04

I\'m trying to make a textfield that limits a user input. I have this code:

 private void jTextField5KeyTyped(java.awt.event.KeyEvent evt) {                          


        
2条回答
  •  迷失自我
    2021-01-07 05:04

    Here's a simple way to do it:

    private void textFieldKeyTyped(java.awt.event.KeyEvent evt) {                       
     if(textField.getText().length()>=2) {  
       evt.consume();
     }
    }
    

提交回复
热议问题