问题
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