调用JEditorPane时,文本/ HTML换行无法换行

问题描述 投票:0回答:1

我使用JEditorPane来显示一些包含HTML标记的文本,

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);

当我启动应用程序时,text/html似乎正确包装,但是当我尝试在运行时设置JEditorPane的值时(例如,通过调用html单击一个表行,得到JEditorPane.setText("some html text")文本),新文本无法换行我看不到整篇文章。

java html swing user-interface textwrapping
1个回答
0
投票

通常这应该有效,但对于某些特定的HTML片段可能会失败。在这种情况下,需要重写HtmlEditorKit.HTMLFactory。您可以设置增强的EditorKit

htmlTextPane.setEditorKit(anEnhancedHtmlEditorKit);

请提供失败的示例HTML。

© www.soinside.com 2019 - 2024. All rights reserved.