Skip to main content

Using java.awt.Image as source for HTML in JLabel?

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2007-12-09

JLabel can show images in the text using HTML <img>. The source of <img> can be an external file or can be located in the classpath. But how to tell the JLabel that the source actually is found in memory already in the form of a java.awt.Image? I'm asking that, because I want to use images provided by the Swing UI, e. g. the Warning / Error / Info icons taken from the operating system at runtime. Those do not have a publicly available address or file name, but solely exist in the form of java.awt.Image. As the JLabel presumable internally is using java.awt.Image anyways, there should be a "non-hack" way to just tell the label to use that given java.awt.Image instance to fulfil the need to load an <img>. But how?