Home > Mobile >  Loading an image in a JEditorPane using html markup
Loading an image in a JEditorPane using html markup

Time:01-24

I'm having some problems with loading an image in a JEditorPane by using the tag. I get the body of the mail from Gmail, which looks like this:

<div dir="ltr"><div><img src="cid:ii_lagwgzau0" alt="test.jpg" width="451" height="338"><br></div><br></div>

I edit the line via code to look like this:

<div dir="ltr"><div><img src="file:///cache/test.jpg" width="451" height="338"><br></div><br></div>

I save the image in the folder /cache, at the same level of /src, but the image just won't load no matter what I try. I also can't figure out if its a path problem or my approach just doesn't work, and I can't find anything that helps online. Anyone knows what I'm doing wrong here?

This is what it looks like graphically:

enter image description here

CodePudding user response:

Remove the three forward slashes between "file:" and the path. Change

<img src="file:///cache/test.jpg">

to

<img src="file:cache/test.jpg">

Found it from this answer: https://stackoverflow.com/a/10084395/7376577

The file structure:

root
├───cache
│       test.jpg
│
└──src
        MyJFrame.java
  • Related