Displaying Local Images in a JTextPane with HTML
Hi guys, I want to be able to display local images in a JTextPane with HTML.
I have the syntax for the IMG tag down, and was able to display images from online. However seeing how there was always a delay in displaying the images from online, I decided to change it so it would check if they were downloaded first, download them if not, and then display them. Downloading them works without a hitch. However I've had trouble trying to get the local images to appear. Looking at other online sources, I've seen that others couldn't just treat the location of an image in an <img> tag the same way as they would a file's location. I do know that when you want to display images from your computer in a web browser, you have to use file://. This still isn't working for me. The closest I've come to was by doing this...
This makes my entire program white (except decorations) for a few seconds before anything appears. I have tried all the possibilities of different / vs \\ combinations without luck. I've also tried setting the JTextPane's HTML document's base key, which appears to give the same effect.
jTextPane1.setText("<img src=\"file://" +
new File("../DVDs/Spider-Man/thumb.jpg").getCanonicalPath().replace(" ","%20").replace("\\","/") + "\">");
Any ideas on how to get these local images to appear? Thanks!
PS: I posted this on another site, but seeing how there are much fewer active users there and it's just a general programming language forum, I figured I needed to make a new thread somewhere else.
Re: Displaying Local Images in a JTextPane with HTML
Found my answer! It starts with "file:/" (not two slashes) and every slash after is also a regular slash instead of a backslash.