帮助编写自己的javax.swing.text.Document [英] Help on writing your own javax.swing.text.Document

查看:68
本文介绍了帮助编写自己的javax.swing.text.Document的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Java TextComponent,其中基础文档具有某种结构.它很短,基本上是一行.我需要能够覆盖对在文档某些部分中插入或删除字符的响应.

I'm writing a Java TextComponent where the underlying document has some structure. It is very short, basically one line. I need to be able to override the response to inserting or deleting characters in some parts of the document.

我最初的方法是实现javax.swing.text.Document,但是这似乎涉及开发许多关联的类(Element,EditorKit,View),并且似乎没有太多的示例或教程. .有很多使用预定义的实现的方法.

My initial approach was to implement javax.swing.text.Document, but this seems to involve developing many associated classes (Element, EditorKit, View) and there don't seem to be many examples or tutorials on how to do this. There are plenty on using the pre-defined implementations.

任何人都可以为我提供一些有关Document的简单实现的教程或其他辅助工具,以及我需要创建哪些其他类才能使其工作.

Can anyone point me at tutorials or other aids for simple implementations of Document and what other classes I need to create to make this work.

推荐答案

如果您只想对字符插入/删除做出反应,那么最好使用DocumentFilter.这样,您可以防止在文档中插入字符.阅读JTextField API并单击文本组件功能"上Swing教程的链接以获取更多信息.

If you just want to react to character insertion/deletion then maybe a DocumentFilter is the better approach. This will allow you to prevent the insertion of characters to the Document is you so desire. Read the JTextField API and follow the link to the Swing tutorial on "Text Component Features" for more information.

这篇关于帮助编写自己的javax.swing.text.Document的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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