本文介绍了将用户的键盘输入过滤到JTextField(swing)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在将键盘输入输入JTextField(swing)之前限制键盘输入

How can I limit the keyboard input before it will be entered into JTextField (swing)

我想允许用户只输入
+ - 0123456789ABCDEF,。 chars,且不超过1 char

I want to allow user to input only"+-0123456789abcdef,." chars, and no more than 1 , or . char

我的JTextField是一行输入字段。

My JTextField is one-line input field.

谢谢!

推荐答案

您可以通过。这允许您控制任何Document类型的文本处理。
或使用

You can achieve this by DocumentFilter. This allows you to control text handling for any Document type.Or use a JFormattedTextField

这篇关于将用户的键盘输入过滤到JTextField(swing)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 17:24
查看更多