Java HTMLDocument (insertAfterEnd, insertAfterStart, insertBeforeEnd, insertBeforeStart) not working?

丶灬走出姿态 提交于 2019-12-05 09:37:17
private HTMLDocument doc;
...
JTextPane jep = jTextPane1;
jep.setContentType("text/html");
jep.setText("<html><table><tr><td>A line of text</td></tr><tr><td>Another line of text</td></tr></table>");
doc = (HTMLDocument)jep.getStyledDocument();

The content type followed by a setText installs the EditorKit and determines the document. For that reason take the StyledDocument afterwards. The setText("...") again ensures that HTML is taken. (You could have a JLabel or JButton with "< html >< b >H< /b >< i >ello< /i >< span style='color: #0ff078' >!!!< /span >".

JTextPane is more high level as JEditorPane (strange naming). It provides StyledDocument by which you could do more.

The rest is okay.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!