是否可以使用JavaFX更改应用程序图标,还是必须使用Swing?


当前回答

如果你有一个图像文件夹并且图标保存在其中,使用这个

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

如果你直接从你的包中使用它,这不是一个好的做法,使用这个

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

如果你有一个文件夹结构里面有你的图标

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

其他回答

stage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("images/icon.png")));

图像文件夹需要在资源文件夹。

stage.getIcons().add(new Image("/images/logo_only.png"));

在src文件夹中创建图像文件夹并从中获取图像是一个好习惯。

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

您可以使用此方法添加多个不同大小的图标。这些图像应该是同一图像的不同大小,并将选择最佳大小。 如。32岁的16 x16 32

我试过了,效果不错:

stage.getIcons().add(new Image(getClass().getResourceAsStream("../images/icon.png")));

如果你有一个图像文件夹并且图标保存在其中,使用这个

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

如果你直接从你的包中使用它,这不是一个好的做法,使用这个

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

如果你有一个文件夹结构里面有你的图标

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