23

I have a simple executable Jar file. How I can set icon for this file? In my case I use the standard Jar icon which I would like to change.

enter image description here

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • 1
    Let's assume you are using Windows. When you installed JRE, the .jar extension got associated to the java binary and got a default icon. This is what you are seeing and you can't override it programmatically in the code of your application. You have to use some other way of hacking, like http://jsmooth.sourceforge.net/ (mentioned by others as well). Anyways you can set the icon provided by your Swing frame the way others told you (the "runtime icon of the window") – gyorgyabraham Nov 25 '13 at 15:38

2 Answers2

21

you can use setIconImage:

frame.setIconImage(
new ImageIcon(getClass().getClassLoader().getResource("PATH/TO/YourImage.png"))
);

Update

If you want to change the coffee-cup then you may use tools like JSmooth to create executable java file and also change the jar file icon.

As you can see in the comments JSmooth can be used for windows operating systems. For Mac you can check the link here on how to change the icon.

For linux OS you can create a desktop launcher and choose an icon image for it.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
tokhi
  • 21,044
  • 23
  • 95
  • 105
  • 11
    It will only change the icon of coffee on the upper left corner and not of the jar file. – Prasad Nov 12 '13 at 11:14
  • he has updated his question. – tokhi Nov 12 '13 at 11:19
  • Yes but how, I would like to configure this during build time. – Peter Penzov Nov 12 '13 at 11:21
  • you can just create the jar file and set the icon with it. – tokhi Nov 12 '13 at 11:57
  • 2
    The same as Prasad: OP is asking for changing the JAR icon which JSmooth doesn't make. JSmooth does create an EXE and sets an icon to it not to the JAR file. Also this solution is intended only to work on Windows OS. I think JSmooth is a good and very valid option but you should state these facts. If you do then I'll be very happy to revoke my downvote. – dic19 Nov 12 '13 at 15:15
  • Thanks! And +1 for Mac and Linux options :) – dic19 Nov 12 '13 at 15:52
  • 1
    Its works on Windows: `setIconImage(new javax.swing.ImageIcon(getClass().getResource("/icon.png")).getImage());` – Marcus Becker Apr 27 '16 at 01:38
6

One of my friends suggested me about JSmooth which can be used to associate icon to a jar file.

You can try this.

Edit:

But this will work only for Windows OS.

PS : This tool can be used to convert jar to exe and then you can set icon to it.

Prasad
  • 1,188
  • 3
  • 11
  • 29
  • 7
    Have you ever used this tool sometime? If so then you know JSmooth doesn't associate an icon to a JAR file. It's a JAR wrapper that generates an EXE file to execute the JAR. You can associate an icon to this EXE file not the JAR file itself. JAR icon still being the coffee-cup. – dic19 Nov 12 '13 at 14:23
  • 1
    @dic19 yes man agreed. but the icon changes which was the requirement. – Prasad Nov 12 '13 at 14:53
  • 9
    No it's not. OP is asking for changing the JAR icon which JSmooth doesn't make. JSmooth does create an EXE and sets an icon to it not to the JAR file. Also this solution is intended only to work on Windows OS. I think JSmooth is a good and very valid option but you should state these facts. If you do then I'll be very happy to revoke my downvote. – dic19 Nov 12 '13 at 15:13