0
我在我的程序下面的代码:图像不显示与setIcon()来
JLabel status = new JLabel();
status.setBorder(BorderFactory.createLineBorder(Color.BLACK));
status.setBounds(400, 30, 380, 200);
status.setIcon(new ImageIcon("C:........./logo2.png"));
status.setLocation(50, 750);
add(status);
但现在我想从setIcon(new ImageIcon("path"))
删除对我有一个文件夹里在我的项目的图像的路径。
我试着这样做:
status.setIcon(new ImageIcon("src/folder/logo2.png"));
但它并没有显示任何内容。
我发现this topic,并试图这也:
ImageIcon(this.getClass().getResource("src/files/logo2.png"));
但它给了我一个空指针。
这是我的项目的结构:
我怎样才能正确显示此图像?
请显示您的项目的文件夹结构。 – 2014-10-02 19:43:19
好吧,我刚刚编辑我的问题 – Rikkin 2014-10-02 19:49:06
你试过'ImageIcon(this.getClass()。getResource(“/ files/logo2.png”));'? – 2014-10-02 19:53:46