How i can set Desktop Icon of my java Application in windows7, 8?

7.7k views Asked by At

I have here nice and working code

InputStream img = Main.class.getResourcesAsStream("/optician/icon.png");
BufferedImage myImg=ImageIO.read(img);
setIconImage(myImg);

and here is also try/catch but i did not write this. So, this is working fine anywhere, in JFrame, in taskbar, everywhere is working fine but in my Desktop is again Java coffee cup, it is not changed with this code. Any idea how i can change Desktop Icon ? I can't find any solution...

2

There are 2 answers

1
PC Luddite On BEST ANSWER

Operating systems assign icons based on file associations. Because your code is compiled to a jar, the OS is going to give it the icon it gives to all jar files.

To give your application a custom icon, you have to compile it to an executable or use an executable to launch the jar. If the OS knows that a file is an executable, it will check to see if it supplies an icon in its binary, and if it doesn't, it will give it the default icon.

There are numerous third party programs that can make executables out of jars. You can search using your favorite search engine to find a suitable program (something along the lines of "jar to executable" or "jar to exe")

1
Rafiq On

For Java coffee cup icon change you can use below code

public class StuInfo extends JFrame {

Container cont;

StuInfo() {
    setIconImage(new ImageIcon(ClassLoader.getSystemResource(
            "images/LOGO000.gif")).getImage());
    setLayout(null);
    cont = getContentPane();
    cont.setLayout(null);
    cont.setBounds(0, 0, 700, 600);
    setSize(600, 500);
    setVisible(true);

 }

public static void main(String args[]) {
    StuInfo s = new StuInfo();
    s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
 }