简体   繁体   中英

How to change executable jar file icon?

I have been able to change the runtime icon using this example like this

getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage(getClass()
.getClassLoader().getResource("MyProject/resources/myIcon.png")));

but is there a way to tell NetBeans to use myIcon.png for the executable jar file (MyProject/dist/MyProject.jar) icon?

A launch wrapper is the solution, I use launch4j, a cross platform lightweight wrapper

launch4j website

您可以使用JSmooth创建可执行的Java文件,并将图标关联到该文件。

No, there isn't, because icon is determined by Java. Only way to do so (at least for Windows) is to use wrapper like launch4j and then set icon path. If you already have wrapped exe with no or wrong icon, you can use Recource Hacker and then follow turtorials on how to change icon. Otherwise, you can't change .jar's icon

A possibility on mac is to use this line:

com.apple.eawt.Application.getApplication().setDockIconImage( new ImageIcon(getClass().getResource( "resources/appIcon.png" )).getImage());

It set your icon for the dock. I can't test it for now, i'm not working on a Mac but try it and get me up do date.

As known, it is not possible to change .jar icon cause if you want to do it you should change all the .jar files in your operating system. Anyhow, a solution is possible. You can create a shortcut for the .jar and then you can change it: Right button >> Properties >> Change Icon.

在此处输入图片说明

ps The icon file should be a .ico, so you can use many site for conversion in .ico extension if your image has got another one.

Alternative 1: You can use also Launch4j, it's most simple way to generate application executable file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM