f.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("logo.gif")));
In the above statement, f is the JFrame object, and logo.gif is the icon's image file, which must be stored in the same folder as the .java file. The file can be of any size, but 32x32 pixels is best. When deploying in a jar, be sure to include the image file as well as the .class file.