在JTextPane中保存Java字体

问题描述 投票:0回答:1

作为使用javax.swing学习Java GUI编程的一部分,我打算用字体保存JTextPane的内容,有什么办法吗?

java jtextpane java-font
1个回答
0
投票

是的,你可以使用HTMLEditorKit或RTFEditorKit来保存JTextPane的内容。

StyledDocument doc = (StyledDocument)textPane.getDocument();

HTMLEditorKit kit = new HTMLEditorKit();

BufferedOutputStream out;

try {
    out = new BufferedOutputStream(new FileOutputStream(new File("rich.html")));

    kit.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());

} catch (FileNotFoundException | IOException e) {
} catch (BadLocationException e) {
}
© www.soinside.com 2019 - 2024. All rights reserved.