JTextPane append HTML string

后端 未结 1 1540
失恋的感觉
失恋的感觉 2021-01-23 03:56

I can parse the content of a JTextPane witout any problems in HTML:

textPane = new JTextPane();
textPane.setContentType(\"text/html\");
textPane.setText(

        
相关标签:
1条回答
  • 2021-01-23 04:32

    Use e.g.

    HTMLDocument doc=(HTMLDocument) textPane.getStyledDocument();
    doc.insertAfterEnd(doc.getCharacterElement(doc.getLength()),"<b>Goodbye!</b>");
    

    Or

    HTMLEditorKit kit=(HTMLEditorKit )textPane.getEditorKit();
    

    and use the method if you would like to insert paragraph/table or another branch element

    public void insertHTML(HTMLDocument doc, int offset, String html,
                           int popDepth, int pushDepth,
                           HTML.Tag insertTag)
    
    0 讨论(0)
提交回复
热议问题