Does swing support *.ico files?

后端 未结 2 1508
南旧
南旧 2020-12-20 13:12

Setting an image for a swing action :

Action action = ...
// ImageIcon icon = new ImageIcon(getClass().getResource(\"/icon.ico\"));
ImageIcon icon = new Imag         


        
2条回答
  •  有刺的猬
    2020-12-20 14:00

    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
    

提交回复
热议问题