How to set application installer icon in JavaFX?

2.6k Views Asked by At

I'm using the JavaFX-Gradle-plugin to build the distribute-able binaries and the installer of a JavaFX application. When my application runs, I'm able to set the icon this way:

stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/isotype.png")));

which correctly sets the icon for the running application:

enter image description here

as well as the task bar:

enter image description here

But how do I set the icons for the start menu:

enter image description here

and potentially other places:

enter image description here

4

There are 4 best solutions below

4
KeatsPeeks On BEST ANSWER

There is a open pull request documenting this here

It says:

Customize Icons

To customize the icons used in a native bundle, you have to provide the icons for the appropriate bundle. The icons must follow the file name convention in order to get picked up.

Tip: Set the verbose setting to true, to have log which files are picked up from your deploy directory.

and for Microsoft Windows in particular:

Windows

Icon location: src/main/deploy/windows

For Windows you can provide two different icons.

  • application icon
  • setup icon - the icon of the installer

| Type | Filename | | :---------------- |:------------------------- | | .exe icon | \<appName>.ico | | setup exe icon | \<appName>-setup-icon.bmp |

Despite what it says there, the correct path is src/main/deploy/packages/windows as show in the adjusted-launcher-icon example.

5
AudioBubble On

Maybe the path of your image ("/isotype.png") is incorrect. Choose one method to give correct path from below options. If icon image is stored:

  • In a folder (e.g. images) then use this path "/images/isotype.png" as like:

    stage.getIcons().add(
          new Image(this.getClass().getResourceAsStream("/images/isotype.png")));
    
  • In package directory then use this path "isotype.png" as like:

    stage.getIcons().add(new Image(this.getClass().getResourceAsStream("isotype.png")));
    
  • In a folder structure then use this path "../images/isotype.png" as like:

    stage.getIcons().add(
          new Image(this.getClass().getResourceAsStream("../images/isotype.png"")));
    

Updated:

You have to take a look at A guide to the Gradle JavaFX Plugin which describes the Javafx packages are complete with cross-platform flair-like start menu integration, dock and tray icons, menu-bar integration, and single click icons. For that you've to Sign your files in the output folder if you plan to distribute the application, stated here in 7.3.5 using signtool.exe.

Now you have to some (icons) configuration options inside of the build.gradle as:

javafx {
    appID 'SampleApp'
    appName 'Sample Application'
    mainClass 'com.example.sample.Main'

    jvmArgs = ['-XX:+AggressiveOpts', '-XX:CompileThreshold=1']
    systemProperties = [ 'prism.disableRegionCaching':'true' ]
    arguments = ['-l', '--fast']

    embedLauncher = false

    // deploy/info attributes
    category = 'Demos'
    copyright = 'Copyright (c) 2013 Acme'
    description = 'This is a sample configuration, it is not real.'
    licenseType = 'Apache 2.0'
    vendor = 'Acme'
    installSystemWide = true
    menu = true
    shortcut = true

    // app icons
    icons {
        shortcut = ['shortcut-16.png', 'shortcut-32.png', 'shortcut-128.png', 'shortcut-256.png', '[email protected]', '[email protected]', '[email protected]']
        volume = 'javafx-icon.png'
        setup = 'javafx-icon.png'
    }

    // applet and webstart stuff
    debugKey {
        alias = 'debugKey'
        //keyPass = 'password' // provide via command line
        keyStore = file('~/keys/debug.jks')
        //storePass = 'password'  // provide via command line
    }
    releaseKey {
        alias = 'production'
        //keyPass = 'password' // provide via command line
        keyStore = file('/Volumes/ProdThumbDrive/production.jks')
        //storePass = 'password'  // provide via command line
    }
    signingMode 'release'

    width = 800
    height = 600
    embedJNLP = false
    codebase = 'http://example.com/bogus/JNLP/Codebase'

    // arbitrary jnlp icons
    icon {
        href = 'src/main/resources/javafx-icon.png'
        kind = 'splash'
        width = 128
        height = 128
    }
    icon {
        href = '[email protected]'
        kind = 'selected'
        width = 16
        height = 16
        scale = 1
    }
}
0
mipa On

The general procedure how to do that is documented here: https://github.com/BilledTrain380/javafx-gradle-plugin/blob/648acafa7198e9bd7cf1a2ef933456ce5e0b65f9/README.md#customize-icons but lately I had problems with the latest version of the packager (actually the ant tasks) to get that working. Something seems to be broken there because it works with older (Java 8) versions of the packager but not with the recent ones. I was able however to get it working by explicitly specifiying

<fx:bundleArgument arg="icon" value="package/macosx/myapp.icns"/>

inside the fx:deploy section. I don't know how do that in Gradle because I used ant but you should be able to find that out. In older versions of the packager this was not necessary.

0
dharav On

if you are using ant build or artifact to build javafx application follow the post might help

https://flaironix.com/2019/09/18/adding-custom-icon-for-javafx-application-exe-file-in-intelije/

ussing this option tag in artifact

<option name="icons">
    <JavaFxApplicationIcons>
    <option name="linuxIcon" value="$PROJECT_DIR$/src/Controller/logo.png" />
    <option name="windowsIcon" value="$PROJECT_DIR$/src/Controller/logo.ico"/>
   </JavaFxApplicationIcons>
</option>