Does swing support *.ico files?

冷暖自知 提交于 2019-12-18 07:36:42

问题


Setting an image for a swing 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 files do not get rendered, only png/jpg.
Is this by design ?


回答1:


The supported types might change by manufacturer and version, though you can usually count on 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);
        }
    }
}

Output here/now

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



回答2:


Natively, no.

How ever, you may like to take a look at image4j which provides (IMHO) excellent support for them



来源:https://stackoverflow.com/questions/12185768/does-swing-support-ico-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!