且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java JTextfields

更新时间:2023-12-05 08:47:22

您可以使用 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.