简体   繁体   English

无法从java.awt.Image转换为Image

[英]cannot convert from java.awt.Image to Image

I am setting icon to my Jlabel in Eclips but it giving error that Type mismatch: cannot convert from java.awt.Image to Image and in next line The constructor ImageIcon(Image) is undefined 我在Eclips中将图标设置为我的Jlabel,但是它给出了类型不匹配的错误:无法从java.awt.Image转换为Image并在下一行中构造函数ImageIcon(Image)未定义

    JLabel label_1 = new JLabel("");
    Image img=new ImageIcon(this.getClass().getResource("/a1.png")).getImage();
    label_1.setIcon(new ImageIcon(img));
    label_1.setBounds(0, 0, 439, 615);
    frame.getContentPane().add(label_1);

Why you don't use Icon instead to Image : 为什么不使用Icon代替Image

Icon icon = new ImageIcon(getClass().getResource("/a1.png"));
label_1.setIcon(icon);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM