こんにちは、JTextPane があり、別の時間にコンテンツ (フォント情報を含むテキスト) をロードしたいと考えています。追加テキストは、フォント名またはサイズ、太字または斜体で常に変更されます。新しい文字列を (diff フォントを使用して) 挿入すると、TextPane は以前に読み込まれたテキストのフォント情報を常に失います。テキストペインのフォント情報を常に保持する方法は? 画像も挿入したい!! そのために HtmlDocument を使用する必要がありますか? どんなアイデアや提案も大歓迎です。前もって感謝します!!JTextPane の私のコードは、
textPane.setText("\n This is sample text editor ex");
styleDoc = textPane.getStyledDocument();
SimpleAttributeSet keyWord = new SimpleAttributeSet();
// set font information for new text
StyleConstants.setFontFamily(keyWord, fontName);
StyleConstants.setFontSize(keyWord, fontSize);
try {
styleDoc.insertString(0,
styleDoc.getText(0, styleDoc.getLength()), null);
styleDoc.insertString(styleDoc.getLength(), "ample", keyWord);
} catch (Exception e) {
e.printStackTrace();
}