Search code examples
javaswingiconsjframeimageicon

Set icon in JFrame


I want to change the icon of the project instead of java icon. When the program icon is being displayed in status bar, it should be displaying the customized icon instead of default java icon.

I am using the following code. Please suggest me what's wrong in this code.

class newframe extends JFrame 
{

    Container cp;
    newframe()
    {
        cp=this.getContentPane();
        cp.setLayout(null);
    }

    public static void main(String args[])
    {
        newframe frm= new newframe(); 

        frm.setbounds(0,0,1000,800);
        frm.setVisible(true);
        ImageIcon im1= new ImageIcon("path upto image");
        frm.setIconImage(im1.getImage());
    }
}

Solution

  • ..new ImageIcon("path upto image"); 
    

    A frame icon will typically be an embedded-resource, so must be accessed by URL rather than (a String representing a path to) a File.