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

Categories

0 votes
660 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...