my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes cant display gif/jpeg in JEditorPane ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cant display gif/jpeg in JEditorPane ?" Watch "cant display gif/jpeg in JEditorPane ?" New topic

cant display gif/jpeg in JEditorPane ?

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
Can someone please tell me how to do this ?
I am using jdk1.4 using full directory path
I am using following code
String text = "<html>\n" + "<font color=red>hi my name is sarim</font>\n" + "<img src=\"/home/masters/2001/sr1305/tomcat/webapps/ROOT/myadmin/graphs/copy.gif\" width=200 height=200></img>";
editorPane = new JEditorPane(type, text);
it shows the font, but shows an empty icon in place of the image....
I have included the full absolute path to the image folder
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I figured it out... the IMG tag can only take the URL of the image... you are giving it a path to the image... here's an example of what to do :

I did find one problem with this though... if you are on a windows system and the file is in any directory or subdirectory that has a space in the name, the generated URL doesn't work... you'd probably have to parse the URL and change all spaces to %20 or something...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: cant display gif/jpeg in JEditorPane ?
It's not a secret anymore!