public LoginFrame() {
super();
this.setIconImage(EditorUtils.createIcon("email.gif").getImage());
getContentPane().setLayout(null);
jFrameValidate();
setTitle("登录邮箱");
JLabel backgroundLabel = new JLabel();
backgroundLabel.setBounds(0, 0, 768, 540);
backgroundLabel.setText("<html><img width=776 height=574 src='"
+ this.getClass().getResource("/loginBg.jpg") + "'></html>");
在myeclipse提示图片加载失败,email.gif放在res文件夹中,res和LoginFrame所处的文件夹src处于同一文件夹中。应该怎么设置路径呢?

解决方案 »

  1.   

    把email.gif入到工程根目录试试
      

  2.   

    如果上面的不爽,你在工程根目录下建立个images目录(即和src目录平级),把图片放里,其它的改动就不说了,你懂的。
      

  3.   

    在论坛里搜索awt或swing图片路径之类的关键词应该能搜到不少答案
      

  4.   

    加入工程根目录下可以加载,但是我把图片都放在了res文件夹下,该如何调用呢?
      

  5.   

    那就用这个xxx.class.getResourceAsInputStream();
      

  6.   

    打错了
    XXX.class.getClassLoader().getResourceAsStream(name)