如何使jtextfield只接受netbeans中的字符 [英] how to make jtextfield only accept characters in netbeans

查看:130
本文介绍了如何使jtextfield只接受netbeans中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了netbeans注册的示例项目。在jtextfield1中是用户ID而Jtextfiled7是国家,两者必须在字符中不是数字或不允许空格和特殊字符。有可能吗?

I have done a sample project in netbeans of registration. In the jtextfield1 is the user id and Jtextfiled7 is country, Both must in characters not in numeric or not allowed spaces and special characters.how it is possible?

推荐答案

@Vivek,

我对你提出的这个问题有了答案。请按照以下说明进行操作。

I have the answer for this question you asked. please do as per following instructions.

在Netbeans中右键单击JTextfield并选择事件>> key >>键,然后在代码之间输入以下代码。以下是仅接受字符的代码

In Netbeans right click on JTextfield and select the events>>key>>key typed and enter the following code between the codes. the following is the code for it for only accept characters

enter code here
char c=evt.getKeyChar();

    if(!(Character.isAlphabetic(c) ||  (c==KeyEvent.VK_BACKSPACE)||  c==KeyEvent.VK_DELETE ))
        evt.consume();

这篇关于如何使jtextfield只接受netbeans中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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