Java JTextfields [英] Java JTextfields
本文介绍了Java JTextfields的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题, 如何确保我的JtextField仅接受数字值? 如果用户输入其他内容,我希望它显示错误消息 谢谢
Just a quick question, How do i ensure my JtextField only accepts numeric values? I want it to to diplsy an error message if the user entered anything else thank you
推荐答案
您可以使用 NumberFormatter
构造它而且只会接受数字.
You can use a JFormattedTextField
. Construct it using a NumberFormatter
and it will only accept numbers.
JFormattedTextField
具有许多可配置的选项,可让您决定如何处理错误的输入.我建议查看文档.
The JFormattedTextField
has a bunch of configurable options that let you decide how bad input is handled. I recommend looking at the documentation.
这篇关于Java JTextfields的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文