如何限制JTextArea只接受一组合法的字符? [英] How to limit a JTextArea to only accept a legal set of characters?

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

问题描述

任何人都知道是否有一种简单的方法来限制JTextArea允许的字符。即类似于使用MaskFormatter的JTextField。

Anybody know if there is an easy way to limit the allowed characters for a JTextArea. I.e. similar to JTextField using MaskFormatter.

具体来说,我想将JTextArea的允许字符限制为仅大写字符,并且只限制非常有限的字符集!#¤%& amp ; /()=

Specifically I want to limit the allowed characters for a JTextArea to only uppercase characters and only a very limited set characters like !"#¤%&/()=

推荐答案

你可能会发现链接文档过滤器有趣。第一个过滤器会自动将小写字符转换为大写字母(包括在上面的链接中),所以用户不必担心这一点,然后第二个过滤器将验证所有字符(您需要自己编写)。

You may find the concept of Chaining Document Filters interesting. The first filter would automatically convert lower case characters to upper case (included in above link) so the user doesn't have to worry about this, then the second filter would validate all the characters (you would need to write your own).

这篇关于如何限制JTextArea只接受一组合法的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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