【发布时间】:2014-04-29 10:15:02
【问题描述】:
我试图在我的JDialog 中加载一张图片。
所以,我尝试了 JLabel 这样的:
ImageIcon icon = new ImageIcon("/sau/se/editor/images/HighBtomStPic.png");
System.out.println("Icon exists: "+(icon != null));
JLabel lblNewLabel = new JLabel();
lblNewLabel.setIcon(icon);
print 给了我true,我没有看到我插入的图片,那我做错了什么?
【问题讨论】:
-
文件
/sau/se/editor/images/HighBtomStPic.png是否真的存在于您的计算机上。 -
考虑使用 ImageIO.read over ImageIcon 来加载图像
-
我改变了它并且它已经工作了,
ImageIcon icon = new ImageIcon(GraphEditor.class .getResource("/sau/se/editor/images/HighBtomStPic.png")); -
请写下您问题的答案,以便您接受。要么,要么删除问题,尽管我敢打赌 eitanfar 不希望看到这种情况发生。 ;)
标签: java swing icons jlabel embedded-resource