JavaFX Application Icon


Question

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

1
156
6/10/2015 10:52:37 AM

Accepted Answer

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")));
212
8/30/2017 10:09:21 PM

I tried this and it totally works. The code is:

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

icon.png is under the same folder as the source files.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon