Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to include image in JEditorPane ?

 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. i am trying to display a .png image, will that
work or will only .gif work ?
2.
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
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic