JTextPane cannot render a concatenated HMTL string

半腔热情 提交于 2019-12-12 01:28:40

问题


If we set the text of a JTextPane with a String with HTML tags, it returns the text with the HTML document tags.

jtextPane.setEditorKit(new HTMLEditorKit());
     String setHTMLText= "I am a String with HTML format...<html><font color="red">COLOUR RED<</font><html>";

    jtextPane.setText(setHTMLText);

jtextPane.getText() returns:

<html>
  <head>

  </head>
  <body>
    I am a String with HTML format...

    <html>
      <head>

      </head>
      <body>
        <font color="red">COLOUR RED</font>
      </body>
    </html>
  </body>
</html>

If I try to further concatenate the returned string, nothing is read after the closing HTML tag, so only the original String will render in the JTextPane.

So is there anyway you can use a JTextPane, or any other swing component, that will take HTML formatted text, allow you to the retrieve the text, concatenate it further with HTML formatted strings, and then rendered it ?

Thanks


回答1:


Its a change in approach, for my design I just added to the JTextPane every time the HTML concatenated string was updated, Answer is here



来源:https://stackoverflow.com/questions/58984995/jtextpane-cannot-render-a-concatenated-hmtl-string

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