这是我的密码。
editPane是JEditorPane。HTMLKit是分配给editPane的HTMLEditorKit。
try
{
HTMLKit.insertHTML(
(HTMLDocument) editPane.getDocument(),
editPane.getCaretPosition(),
"test", 0, 0, HTML.Tag.B);
}
catch (Exception exc)
{
// TODO Auto-generated catch block
exc.printStackTrace();
}
System.out.println(editPane.getText());我从短信开始--你好。
我希望看到文本hello 测试。
但是,没有插入粗体文本。我怎么让它做我想做的?
发布于 2019-11-15 17:38:53
尝试:
String text = "<b>bold";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
System.out.println( textPane.getText() );或
String text = "<b>bold";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, HTML.Tag.B);
System.out.println( textPane.getText() );文本窗格的输出将显示使用"null“或HTML标记之间的区别。
我不太理解该方法最后3种方法的功能。
https://stackoverflow.com/questions/58880554
复制相似问题