JavaFX Application Icon

2019-01-08 04:44发布

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

17条回答
smile是对你的礼貌
2楼-- · 2019-01-08 05:19
stage.getIcons().add(new Image("/images/logo_only.png"));

It is good habit to make images folder in your src folder and get images from it.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-08 05:21

What do you think about creating new package i.e image.icons in your src directory and moving there you .png images? Than you just need to write:

Image image = new Image("/image/icons/nameOfImage.png");
primaryStage.getIcons().add(image);

This solution works for me perfectly, but still I'm not sure if it's correct (beginner here).

查看更多
Explosion°爆炸
4楼-- · 2019-01-08 05:24

I tried this and it works:

stage.getIcons().add(new Image(getClass().getResourceAsStream("../images/icon.png")));
查看更多
甜甜的少女心
5楼-- · 2019-01-08 05:24

Image image3 = new Image("Path");
stage.getIcons().add(image3);

查看更多
叼着烟拽天下
6楼-- · 2019-01-08 05:25
stage.getIcons().add(new Image(<yourclassname>.class.getResourceAsStream("/icon.png" )));

You can add more than one icon with different sizes using this method.The images should be different sizes of the same image and the best size will be chosen. eg. 16x16, 32,32

查看更多
地球回转人心会变
7楼-- · 2019-01-08 05:25

I used this in my application

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

Here window is the stage.

查看更多
登录 后发表回答