Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does swing support *.ico files?

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 ?

like image 766
Bax Avatar asked Aug 29 '12 20:08

Bax


2 Answers

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
like image 108
Andrew Thompson Avatar answered Nov 16 '22 22:11

Andrew Thompson


Natively, no.

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

like image 8
MadProgrammer Avatar answered Nov 16 '22 22:11

MadProgrammer