Search code examples
javaimageswingjframeembedded-resource

SetIconImage from Images in the resource


I have A swing Application that has an Image Folder in the resources. I use the Following Piece of code to access the Images:

btnDel = new JButton(new ImageIcon(getClass().getResource("/Recycling-Pool.png")));

This Methods Works fine For me in reference to Images for Components such as JLabels and JMenuItems. I have an Icon for the Application which I access using the Following Code:

setIconImage(getToolkit().getImage("Images/Free bsd.gif"));

This Also works fine for the Bar Icon, But I want the Icon Also Bundled together With the Apllication and I can't figure Out How to access the Icon Image for the Application Bar. Please Help.


Solution

  • I figured Out the Answer. Sorry for Wasting your time. It will be like this:

    setIconImage(getToolkit().getImage(getClass().getResource("/Free bsd.gif")));
    

    This works fine for me for an embedded Image. :)