JavaFX Application Icon

Sebb77 picture Sebb77 · Apr 12, 2012 · Viewed 143.3k times · Source

Is it possible to change the application icon using JavaFX, or does it have to be done using Swing?

Answer

Michael Berry picture Michael Berry · Apr 12, 2012

Assuming your stage is "stage" and the file is on the filesystem:

stage.getIcons().add(new Image("file:icon.png"));

As per the comment below, if it's wrapped in a containing jar you'll need to use the following approach instead:

stage.getIcons().add(new Image(<yourclassname>.class.getResourceAsStream("icon.png")));