Set Icon for executable Jar file
Solution 1
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.
Solution 2
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.
Related videos on Youtube

Peter Penzov
Updated on July 07, 2020Comments
-
Peter Penzov over 2 years
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.
-
gyorgyabraham about 9 yearsLet'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 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")
-
-
Prasad about 9 yearsIt will only change the icon of coffee on the upper left corner and not of the jar file.
-
tokhi about 9 yearshe has updated his question.
-
Peter Penzov about 9 yearsYes but how, I would like to configure this during build time.
-
tokhi about 9 yearsyou can just create the jar file and set the icon with it.
-
dic19 about 9 yearsHave 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.
-
Prasad about 9 years@dic19 yes man agreed. but the icon changes which was the requirement.
-
dic19 about 9 yearsNo 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 about 9 yearsThe 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.
-
tokhi about 9 years@dic19: I updated the post.
-
dic19 about 9 yearsThanks! And +1 for Mac and Linux options :)
-
Marcus Becker over 6 yearsIts works on Windows:
setIconImage(new javax.swing.ImageIcon(getClass().getResource("/icon.png")).getImage());