JTextField limit input to certains chars only

后端 未结 2 1299
天命终不由人
天命终不由人 2021-01-19 02:09

i\'d like to create JTextField with input characters limited to someting like \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYWZZ0123456789+&@#/%?=~_-|!:,.;\" so i t

相关标签:
2条回答
  • 2021-01-19 03:10

    maybe better would be use DocumentFilter with Pattern,

    0 讨论(0)
  • 2021-01-19 03:16

    Try a JFormattedTextField and use

    MaskFormatter mf = new MaskFormatter();
    mf.setValidCharacters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYWZZ0123456789+&@#/%?=~_-|!:,.;");
    JFormattedTextField textField = new JFormattedTextField(mf);
    

    Edit: Sorry, that was the wrong code, here's the working one

    0 讨论(0)
提交回复
热议问题