Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...