Thursday, January 24, 2002 12:47 PM
You can display either GIFs or JPEGs in AWT. This includes GIFs with transparent areas - although they would still be handled as having rectangular areas.
Since regular AWT components are knowns as heavyweight - whcih means that they have to have an opaque background, you must create your own lightweight AWT component - and that component will contain your GIF - and THEN it will appear with its transparent areas.
To create a lightweight component, create a class that extends either java.awt.Component or java.awt.Container (normally java.awt.Component).
class LightWeight extends Component
private String pathToImage; // this is the GIF
private Image theImage;
public LightWeight(String image)
pathToImage = image;
public void paint (Graphics g)
theImage = Toolkit.getDefaultToolkit().getImage(pathToImage);
g.drawImage(theImage, 0, 0, this);
public Dimension getPreferredSize()
return new Dimension (
This should be a start...