【发布时间】:2015-02-15 05:38:39
【问题描述】:
我可以解析 JTextPane 的内容,而不会出现 HTML 中的任何问题:
textPane = new JTextPane();
textPane.setContentType("text/html");
textPane.setText(<b>Hello!</b>);
// ...
setVisible(true);
这导致
你好!
但每当我尝试将字符串附加到 textPane 时,使用
styledDoc = (StyledDocument) textPane.getStyledDocument();
styledDoc.insertString(styledDoc .getLength(), <b>Goodbye!</b>, null );
(如in this question所见),我的输出是
你好!
<b>Goodbye!</b>
(不带空格) - 因此跳过 html 格式。
如何将字符串附加到我的 JTextPane 对象并保留添加部分的 HTML 格式?
【问题讨论】:
标签: java html formatting append jtextpane