swing是否支持*.ico文件?

Bax*_*Bax 11 java icons swing image

为摆动动作设置图像:

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);
Run Code Online (Sandbox Code Playgroud)

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

And*_*son 13

制造商和版本可能会更改支持的类型,但您通常可以依赖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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出/现在

This JRE supports image types:
Type: bmp
Type: jpg
Type: wbmp
Type: jpeg
Type: png
Type: gif
Run Code Online (Sandbox Code Playgroud)


Mad*_*mer 8

本地,没有.

但是,您可能想看看image4j,它为(IMHO)提供了极好的支持