Martin Pfeffer
Martin Pfeffer

Reputation: 12627

How to set an app icon in JavaFX

I am programming a JavaFX app for windows and want to see an app icon in these situations

  1. shortcut icon (on desktop, windows start menu)
  2. taskbar icon (even when the app is pinned to the task-bar)
  3. (optional) the .exe-icon

The following code seems to do its job quite nice, but when the app is running and I press right to the taskbar to choose "pin this program" the default coffee cup is shown again. The cup is shown in the moment when the taskbar-item is right-clicked -.-

visibleStage.getIcons().add(new Image(this.getClass().getResourceAsStream("JavaFXApp.png")));

I tried to build the app by configuring the Artifact in IntelliJ (JavaFX-plugin) and I also deployed the app with the javafx-maven-plugin...

I also followed some instructions I found in the net and here on stackoverflow, but nothing really helps (see here to get an idea, what I tried). Building the app by Ant doensnt work right now, IntelliJ gives a lot of errors using this build tool.

Thanks in advance.

EDIT: It's getting silly.. After zooming in the output folder the correct .ico of the .exe will be shown. Inconstancy at it's best.

Here the half-working config:

enter image description here

Upvotes: 0

Views: 3337

Answers (1)

Psychokiller1888
Psychokiller1888

Reputation: 650

Well, to add an icon to the app, you just need as you said to .add() an icon as:

primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));

For your installer, and all, I can't really help, but the way I do it works, I'm using innosetup to generate my exe packages, and it's really easy to set it an icon. You can find informations about it on that site I learned about inno setup:

http://code.makery.ch/library/javafx-8-tutorial/part7/

The whole page is about deployment using ant and inno setup to build the exe

Upvotes: 3

Related Questions