Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

java - What are EditorKits in JTextComponents and what is their job?

I'm studying about the structure of text components in Swing programs.

As far as I understand, JTextComponent is essentially divided into a view and a model. The model is an instance of a class implementing Document, containing all of the text and offering ways to manipulate it, and the View presenting the text visually.

However I don't understand exactly where, how and why an EditorKit is used. I'm not sure if it encapsulates ('owns') the model (Document), or if the Document encapsulates it. And not sure where the view fits inside all of this.

So two questions:

1- Please describe the relations between the view, Document and EditorKit in JTextComponents. What encapsulates what, what interacts with what, and why?

2- Please explain the functionality and role of EditorKit.

Thank you for your help

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EditorKit is the abstract parent of DefaultEditorKit and StyledEditorKit, both of which export useful Action classes that operate on the Document model common to text components. In this example, editor kit actions update the Document, which indirectly updates the listening view component. Charles Bell's HTMLDocumentEditor, cited here, is a related example.

image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...