カスタムスイングドキュメント構造を作成する方法
-
27-10-2019 - |
質問
私は持っています JEditorPane
カスタムを保持します EditorKit
そしてカスタム Document
(defaultStyledDocumentから派生)。
以下は、 JEditorPane
:
最初 段落
2番目の段落
上記の例では、次のXML相当の文書構造を取得します。
<root>
<section>
<paragraph>
<content>first</content>
<content bold="true">paragraph</content>
</paragraph>
<paragraph>
<content>second paragraph</content>
<content>\n</content>
</paragraph>
</section>
</root>
上記のタグ名はelement.getName()関数によって決定されることに注意してください。
私の意図は、この構造をカスタム要素タイプで拡張して、スタイルのテキスト以外のコンテンツを編集することです。
例としては、編集者がこのようなXML構造を取得するために音楽ノートエディターに拡張することです。
<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>
私が見るように、スタイルと段落の要素は、document.insertString()およびdocument.setcharacterattributes()メソッドに作成されます。
私の問題は、これらのメソッド(またはペンダントを書く)をデフォルトの構造に戻さずにカスタム要素の種類を使用する方法を無視する方法がないということです。
これが正しいアプローチであるかどうかさえわかりません。カスタムドキュメント構造を作成するには、ドキュメントインターフェイスの独自の実装を作成する必要がありますか?
解決
テーブルの作成の例を参照してください。http://java-sl.com/jeditorpanetables.html
同じ定義する目的の構造を使用できます。
所属していません StackOverflow