Set Icon for executable Jar file

94,014

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.

Share:
94,014

Related videos on Youtube

Peter Penzov
Author by

Peter Penzov

Updated on July 07, 2020

Comments

  • Peter Penzov
    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.

    enter image description here

    • gyorgyabraham
      gyorgyabraham about 9 years
      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 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 years
    It will only change the icon of coffee on the upper left corner and not of the jar file.
  • tokhi
    tokhi about 9 years
    he has updated his question.
  • Peter Penzov
    Peter Penzov about 9 years
    Yes but how, I would like to configure this during build time.
  • tokhi
    tokhi about 9 years
    you can just create the jar file and set the icon with it.
  • dic19
    dic19 about 9 years
    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.
  • Prasad about 9 years
    @dic19 yes man agreed. but the icon changes which was the requirement.
  • dic19
    dic19 about 9 years
    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
    dic19 about 9 years
    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.
  • tokhi
    tokhi about 9 years
    @dic19: I updated the post.
  • dic19
    dic19 about 9 years
    Thanks! And +1 for Mac and Linux options :)
  • Marcus Becker
    Marcus Becker over 6 years
    Its works on Windows: setIconImage(new javax.swing.ImageIcon(getClass().getResource("/icon.png")).g‌​etImage());