Does swing support *.ico files?

后端 未结 2 1509
南旧
南旧 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 13:46

    Natively, no.

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

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题