Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JEditorPane and images via the IMG tag  RSS feed

Kerry Shetline
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!