Question

I have a JEditorPane holding a custom EditorKit and a custom Document (derived from DefaultStyledDocument).

The following is an example for the content of the JEditorPane:


first paragraph

second paragraph


For the example above I get a document-structure with the following XML-equivalent:

<root>
    <section>

        <paragraph>
            <content>first</content>
            <content bold="true">paragraph</content>
        </paragraph>

        <paragraph>
            <content>second paragraph</content>
            <content>\n</content>
        </paragraph>

    </section>
</root>

Note that the tag names above are determined by the Element.getName() function.

My intention is, to extend this structure by custom element types to edit content other than styled text.

An example would be extending the editor to be a music-note editor to get an XML-structure like this:

<root>
    <section>

        <paragraph>
            <content>first</content>
            <content bold="true">paragraph</content>
        </paragraph>

        <musicnotes>
            <bar>
                <note>C</note>
                <note>D</note>
                <note>E</note>
            </bar>
        </musicnotes>

    </section>
</root>

As I see it, the Style- and Paragraph-Elements are created upon Document.insertString() and Document.setCharacterAttributes() methods.

My problem is that I have no clue how to override these methods (or write pendants) to not to go back to the default structure but to use custom element kinds.

At all I don't even know if this is the correct approach. Do I have to create my very own Implementation of the Document-interface to create a custom document structure?

Was it helpful?

Solution

See the example of tables creation. http://java-sl.com/JEditorPaneTables.html

You can use the same defining desired structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top