Is there any way to accept only numeric values in a JTextField?

前端 未结 19 1904
陌清茗
陌清茗 2020-11-22 03:10

Is there any way to accept only numeric values in a JTextField? Is there any special method for this?

相关标签:
19条回答
  • 2020-11-22 04:16

    write this code into key typed

    char c=evt.getKeyChar();
    if(!(Character.isDigit(c) || (c==KeyEvent.VK_BACK_SPACE || c==KeyEvent.VK_DELETE)))
    {
        getToolkit().beep();
        evt.consume();
    }
    
    0 讨论(0)
提交回复
热议问题