Java swing支持*.ico文件吗?

Java swing支持*.ico文件吗?,java,image,swing,icons,Java,Image,Swing,Icons,设置回转动作的图像: 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。 这是故意的

设置回转动作的图像:

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。
这是故意的吗

不是天生的


不过,您可能想看看哪些(IMHO)为它们提供了出色的支持

受支持的类型可能会因制造商和版本而异,尽管您通常可以使用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);
        }
    }
}
此处/现在输出
这很可悲
ico
文件允许您使用不同的、更合适的图像以获得不同的分辨率。@TomášZato可能,但Windows和MacOS都有自己的图标格式:P。还有一些库允许您使用SVG a(矢量)图像,但是您需要仔细研究才能找到thoseI,我刚刚用Oracle Java 8u74运行了这个测试,它仍然只支持这6种格式。@RAnders00在J2SE中对图像类型的支持不是很好,请注意,在另一个操作系统上可能会有所不同(所以不要假定该集是“给定的”)。OTOH将JAI添加到运行时类路径中,该列表不仅应该显著更长,而且在整个操作系统中也应该更加一致。
This JRE supports image types:
Type: bmp
Type: jpg
Type: wbmp
Type: jpeg
Type: png
Type: gif