JavaFX Application Icon

后端 未结 17 1718
滥情空心
滥情空心 2020-11-28 02:25

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

17条回答
  •  佛祖请我去吃肉
    2020-11-28 02:32

    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(.class.getResourceAsStream("icon.png")));
    

提交回复
热议问题