Search code examples
javasvgiconsjlabelbatik

How to set a transparent Icon from a transparent SVG file


I have a transparent SVG file. I would like to use it as the icon of a JLabel, via setIcon().

I use Batik for SVG, but I don't know how to do this. Can you help me ?

Thanks :)


Solution

  • I have found the solution :

    SVG r = new SVG(new File(*something*).toURI().toString());
    BufferedImage img = r.createBufferedImage();
    this.enabledIcon = new ImageIcon(img);
    label.setIcon(img);