简体   繁体   English

如何在NetBeas中进行jtextField焦点事件

[英]How to jtextField focus event in NetBeas

I made a landing interface in Java using NetBeans. 我使用NetBeans在Java中创建了一个登陆界面。 I want to set when the textfield input format does not meet the requirements, then Red tips occur, how to achieve this? 我要设置文本字段输入格式不符合要求时,然后出现红色提示,如何实现? I know it is related to focus event, but I do not know the details 我知道这与焦点事件有关,但我不知道细节

在此处输入图片说明

I suggest that use ActionEvent and ActionListener for textfield. 我建议对文本字段使用ActionEvent和ActionListener。

then use textfield.getText() to get String data. 然后使用textfield.getText()获取String数据。

you can now examine the String's content by separate it. 您现在可以通过分开检查字符串的内容。

If you wanna check the format is a number or not, just use NumberFormatException. 如果要检查格式是否为数字,请使用NumberFormatException。

https://docs.oracle.com/javase/7/docs/api/java/lang/NumberFormatException.html https://docs.oracle.com/javase/7/docs/api/java/lang/NumberFormatException.html

after that, 之后,

you want a red warning tip, use label with color red, and .setVisible(boolean) to control it shows or not. 您需要红色警​​告提示,请使用带有红色的标签,并使用.setVisible(boolean)来控制是否显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM