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 JEditorPane and images via the IMG tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane and images via the IMG tag" Watch "JEditorPane and images via the IMG tag" New topic

JEditorPane and images via the IMG tag

Kerry Shetline

Joined: Feb 09, 2006
Posts: 14
I'm trying to use the IMG tag to add images to an HTML JEditorPane, and I've run into some questions and issues.

1) I can easily grab an image when I set the SRC attribute of an IMG tag to a full URL, but I want to use a local resource from my application's JAR file instead, not something hosted out on some web site somewhere? I'd rather not have to use a 'file://' URL that's going to have to be different for applet vs. stand-alone application implementations, that's not going to have to be different when I'm running in my IDE (with no JAR file built yet) vs. or running a fully built and deployed application.

2) What can I do, if anything, to include images created at run time, which don't exist in any form other than a run-time BufferedImage? Can I intercept URL processing somehow (overriding JEditorPane.getStream() didn't work) so I can control the image loading process?

3) What's up with how the ALIGN attribute of an IMG is interpreted? An alignment of 'top' looks like it aligns the top of an image with the baseline of the surrounding text instead of the top of the text line (completely useless!), 'middle' looks like it's doing what it's supposed to do (but it isn't a very useful alignment), and 'bottom' makes the bottom of my images ride about one or two pixels above the text baseline instead of right on the baseline.

The most useful alignment for me would be for the middle of an image to be aligned with the middle of the text ascent, not including padding for diacritical marks -- but even regular web browsers and the standard HTML/CSS specs don't support that particular alignment, much to my dismay.

At any rate, can the ALIGN behavior be overridden? I suspect that such a thing is probably buried too deeply in the Swing implementation to change without rewriting half of the Swing code, unfortunately.
I agree. Here's the link:
subject: JEditorPane and images via the IMG tag
It's not a secret anymore!