如何过滤JTextField中的某些字符 [英] how to filter certain characters in JTextField

查看:143
本文介绍了如何过滤JTextField中的某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何阻止用户输入'JTextField'中的某些字符,如果输入该字符,则不要在文本字段中显示

How to prevent user from entering certain charcters in 'JTextField' and if enters that character is entered ,do not show it in the textfield

推荐答案

JTextField textField = new JTextField(10);
textField.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
  char c = e.getKeyChar();
  if (//Write your condition here) {
     e.consume();  // ignore event
}});

更多相同 here

这篇关于如何过滤JTextField中的某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆