文档过滤器在 Java 中不起作用?
在超过 10 个字符的文本字段中,它必须显示错误。为此,我使用了文档过滤器:
JTextField field = (JTextField) txtFld;
AbstractDocument document = (AbstractDocument) field.getDocument();
document.setDocumentFilter(new DocumentSizeAndUppercaseFilter(10));
所以这是我的文档过滤器编码。我通过文档过滤器注册了文本字段。但这里什么也没发生。如何使用文档过滤器?
DocumentSizeAndUppercaseFilter 类有错误消息。
In text field more than 10 characters na, it has to show an error. For that i used document filter:
JTextField field = (JTextField) txtFld;
AbstractDocument document = (AbstractDocument) field.getDocument();
document.setDocumentFilter(new DocumentSizeAndUppercaseFilter(10));
So this is my document filter coding. I registered the textfield through document filter. But nothing has happening here. How to use document filter?
DocumentSizeAndUppercaseFilter class which has the error msg.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到
DocumentSizeAndUppercaseFilter
的代码,我怀疑您没有实现(/覆盖)DocumentFilter
的替换
方法:以下代码的屏幕截图:
DocumentSizeAndUppercaseFilter
的示例实现:示例
main:
Without seeing the code for
DocumentSizeAndUppercaseFilter
I would suspect that you havn't implemented (/override) theDocumentFilter
'sreplace
method:Screenshot from the code below:
Example implementation of
DocumentSizeAndUppercaseFilter
:Example
main
:从简单的事情开始。
Swing 教程中关于实现文档过滤器的部分有一个工作示例可以完成您想要的一半工作。
Start with something simple.
The section from the Swing tutorial on Implementing a Document Filter has a working example that does half of what you want.