Results 1 to 2 of 2
  1. #1
    Pluto is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default 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...

    Java Code:
    jTextPane1.setText("<img src=\"file://" +
    new File("../DVDs/Spider-Man/thumb.jpg").getCanonicalPath().replace(" ","%20").replace("\\","/") + "\">");
    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.

    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.

  2. #2
    Pluto is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default 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.

Similar Threads

  1. Replies: 0
    Last Post: 10-10-2011, 10:00 PM
  2. Showing html in JTextPane directly from a String
    By ni4ni in forum AWT / Swing
    Replies: 1
    Last Post: 04-11-2011, 12:03 PM
  3. jTextPane doesn't show HTML
    By indra-uolles in forum AWT / Swing
    Replies: 5
    Last Post: 08-31-2010, 02:29 PM
  4. LineNumber JTextPane html Content
    By mcjava in forum AWT / Swing
    Replies: 3
    Last Post: 08-31-2009, 02:38 AM
  5. how to show a html document on JTextPane
    By mary in forum Advanced Java
    Replies: 2
    Last Post: 08-02-2007, 01:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •