相关疑难解决方法(0)

HTML 嵌入式 Base64 图像的 JEditorPane 内容类型

我正在使用 JeditorPane 和 JEditorKit 来显示一些 HTML。HTML 显示正确,但图像显示为损坏(它们在浏览器中正确显示)。图像 src 是 base64。我这样设置内容类型:

final JEditorPane ed=new JEditorPane();
ed.setContentType("text/html");
Run Code Online (Sandbox Code Playgroud)

我猜是因为它同时包含文本和图像,所以内容类型不正确。如果是这样,它应该设置为什么?TIA。

** 马杜山佩雷拉回复后**

final JEditorPane ed=new JEditorPane();
ed.setContentType("text/html");
ed.setEditable(false);
HTMLDocument html=(HTMLDocument) ed.getDocument();
html.putProperty("IgnoreCharsetDirective", new Boolean(true));
HTMLEditorKit htmle=(HTMLEditorKit) ed.getEditorKit();
try {
    htmle.insertHTML(html,html.getLength(),content,0,0,null);
} catch (BadLocationException | IOException e) {
    // Should not get here
    e.printStackTrace();
}
ed.addHyperlinkListener(new HyperlinkListener() {
          public void hyperlinkUpdate(final HyperlinkEvent pE) {
              if (HyperlinkEvent.EventType.ACTIVATED == pE.getEventType()) {
                  String desc = pE.getDescription();
                  if (desc == null || !desc.startsWith("#")) return;
                  desc = desc.substring(1);
                  ed.scrollToReference(desc);
              } …
Run Code Online (Sandbox Code Playgroud)

html java swing image jeditorpane

1
推荐指数
1
解决办法
1150
查看次数

标签 统计

html ×1

image ×1

java ×1

jeditorpane ×1

swing ×1