简体   繁体   中英

Custom exe icon in Netbeans native package for Swing Application

I want to use my icon in native packaging for java Swing application. There is no option for setting Application icon in properties. There is by default available for JavaFX applications. I need it for Swing having custom exe icon.

Inno setup is used for native packaging in netbeans 8.0.2.

Application icon is in Java Coffee cup icon. I can able to set the frame icon, but I need to set it for generating exe.

My swing application icon

My actual configuration is Netbeans 8.01 with JDK 8 on windows 10
If you look inside your project, there is a subfolder nbproject that contains build directives. A close look at the file build-native.xml give you that:

if(isTrue(nativeEnabled) && defined(nativeType) && nativeType != "none") {
                var icon = new String(project.getProperty("deploy.icon.native"));
                if(defined(icon)) {
                    if(isTrue(fx_ant_api_1_2) && !isTrue(have_jdk_pre7u14)) {
                        var dicon = derelativizePath(icon);
                        // create temporary icon copy renamed to application name (required by native packager)

so you have to add a line in YourProjectFolder/project.properties and it must be like: deploy.icon.native=C:\\\\Path\\\\of\\\\the\\\\icon\\\\yourIcon.ico (path double slashed)
After that you will be able to see the generated file with yourIcon provided.

In your main Frame (In Navigation Window generally in the lower left) Click the JFrame to get the JFrame Options.

In the properties window (generally in the lower right) Go to Other Properties group->IconImage (Click the button (...) )

Choose custom code and there put something like:

new ImageIcon(getClass().getResource("/resources/images/Image.png")).getImage()

Note that this image is in the classpath and is the path of the image in your JAR file.

So if you have the project package like org.myPackage in your directory /home/user/Projects/myProj/org/myPackage You must have other directory /home/user/Projects/myProj/resources/images/ with this image.

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