直接上代码:
URL url=this.getClass().getResource("/images/logo.png");
ImageIcon imageIcon = new ImageIcon(url);
Image img = imageIcon.getImage();
img = img.getScaledInstance(130, 60, Image.SCALE_DEFAULT);
imageIcon.setImage(img);
lblNewLabel_1 = new JLabel(imageIcon);
lblNewLabel_1.setBounds(629, 368, 161, 96);
jp2.add(lblNewLabel_1);
关键代码: URL url=this.getClass().getResource("/images/pwclogo.png");不能直接使用路径要经过这步处理。
另外images是项目src目录下的一个文件夹