File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes how to include image 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 "how to include image in JEditorPane ?" Watch "how to include image in JEditorPane ?" New topic

how to include image in JEditorPane ?

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
1. i am trying to display a .png image, will that
work or will only .gif work ?
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

You'll have to use the add-on JAI (Java Advanced Imaging) API, or the new (JDK 1.4+) ImageIO classes to open and display a PNG image... the pre-1.4 JDKs only supported GIF and JPG images "out of the box".

Ohh... just looked at the #2 part of your question... I'm not sure if the JEditorPane HTMLEditorKit would be able to support PNG if it was able to find the JAI PNG loaders or not... maybe it will... if not you'll have to write a new HTML editor kit to support PNGs once you are able to load them...
[ August 15, 2002: Message edited by: Nathan Pruett ]

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