是否可以使用JavaFX更改应用程序图标,还是必须使用Swing?
当前回答
我试过了,效果很好。代码是:
stage.getIcons().add(
new Image(
<yourclassname>.class.getResourceAsStream( "icon.png" )));
Icon.png和源文件在同一个文件夹下。
其他回答
假设你的stage是“stage”,文件在文件系统上:
stage.getIcons().add(new Image("file:icon.png"));
根据下面的评论,如果它被包装在一个容器中,你将需要使用以下方法:
stage.getIcons().add(new Image(<yourclassname>.class.getResourceAsStream("icon.png")));
我试过了,效果不错:
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")));
我在我的应用程序中使用了这个
Image icon = new Image(getClass().getResourceAsStream("icon.png"));
window.getIcons().add(icon);
这个窗口就是舞台。
stage.getIcons().add(new Image("/images/logo_only.png"));
在src文件夹中创建图像文件夹并从中获取图像是一个好习惯。
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap