11

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

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • I know how to do it in `javapackager`. Does it help, or you need the Gradle solution (of which i'm unsure)? – Mordechai Dec 18 '17 at 19:28

4 Answers4

5

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.

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
KeatsPeeks
  • 19,126
  • 5
  • 52
  • 83
  • Thanks. I didn't know about verbose. That icon location doesn't seem to be the correct one (I tried it and it didn't work) and verbose pointed me to this: Using default package resource [application icon] (add package/windows/Dashman.ico to the class path to customize). So far, putting that on resources and src hasn't working. I'm still playing with it. – Pablo Fernandez Dec 19 '17 at 15:01
  • I also tried deploy/windows/Dashman.ico in many directories and didn't have any effect. – Pablo Fernandez Dec 19 '17 at 15:22
  • I found the correct path, edited this question and also added a comment to the pull request. – Pablo Fernandez Dec 20 '17 at 11:31
  • @Pablo awesome ! – KeatsPeeks Dec 20 '17 at 11:33
3

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', 'shortcut-16@2x.png', 'shortcut-32@2x.png', 'shortcut-128@2x.png']
        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 = 'shortcut-32@2x.png'
        kind = 'selected'
        width = 16
        height = 16
        scale = 1
    }
}
  • The path is correct, that code is only active when the application runs while the start menu and list of programs to uninstall doesn't need the app running. I updated the answer to show that it works when the app is running. – Pablo Fernandez Dec 19 '17 at 14:29
  • No, because it's not applicable. – Pablo Fernandez Dec 19 '17 at 15:05
  • try yo change your directory in `stage.getIcons().add(new Image(this.getClass().getResourceAsStream("isotype.png")));` and make a binaries? –  Dec 19 '17 at 15:07
  • Application code will have no effect on start menu. If I remove the "/", it just fails to find the icon when it starts. – Pablo Fernandez Dec 19 '17 at 15:16
  • @Pablo you can didn't checked a link *A guide to the Gradle JavaFX Plugin* in my answer which also describes the correct path for cross-platforms (Windows or Mac) ? –  Dec 21 '17 at 06:54
0

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.

mipa
  • 10,369
  • 2
  • 16
  • 35
0

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>
dharav
  • 41
  • 4