I have am using JEditorPane to display some text that contain the HTML tag,
JEditorPane htmlTextPane = new JEditorPane();
htmlTextPane.setContentType("text/html");
htmlTextPane.setText("This text pane contains html. The custom HTMLEditorKit supports single letter wrapping.");
final JScrollPane editorScrollPane = new JScrollPane(htmlTextPane);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
When I start the application, the text/html
seems to wrap properly, but when I try to set the value of the JEditorPane
in runtime (for example click a table row, that get the html
text) by calling JEditorPane.setText("some html text")
, the new text fails to wrap and I do not see the whole text.
Normally this should work, but it may fail for some specific HTML snippet. In such a case a rewrite of HtmlEditorKit.HTMLFactory is needed. You can set an enhanced EditorKit by
htmlTextPane.setEditorKit(anEnhancedHtmlEditorKit);
Please provide sample HTML which fails.