gpt4 book ai didi

java - swing 是否支持 *.ico 文件?

转载 作者:搜寻专家 更新时间:2023-10-30 21:20:03 24 4
gpt4 key购买 nike

为挥杆 Action 设置图像:

Action action = ...
// ImageIcon icon = new ImageIcon(getClass().getResource("/icon.ico"));
ImageIcon icon = new ImageIcon(getClass().getResource("/icon_16x16.png"));
action.putValue(Action.SMALL_ICON, icon);

*.ico 文件不会被渲染,只有 png/jpg。
这是设计使然吗?

最佳答案

支持的类型可能因制造商和版本而异,但您通常可以依靠 PNG、JPG 和 GIF。

import javax.imageio.ImageIO;

public class QuickTest {

public static void main(String[] args) throws Exception {
String[] types = ImageIO.getReaderFileSuffixes();
System.out.println("This JRE supports image types:");
for (String type : types) {
System.out.println("Type: " + type);
}
}
}

在这里/现在输出

This JRE supports image types:
Type: bmp
Type: jpg
Type: wbmp
Type: jpeg
Type: png
Type: gif

关于java - swing 是否支持 *.ico 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12185768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com