<分区>
我正在尝试将图像设置为 JLabel,在我的项目中我有一个文件夹“images”,其中是 logo.png
我正在使用下面的代码来获取它
BufferedImage myPicture = null;
try {
myPicture = ImageIO.read(new File("images/logo.png"));
} catch (IOException e1) {
e1.printStackTrace();
}
JLabel headerImage = new JLabel(new ImageIcon(myPicture));
此文件在 eclipse 中有效,但在可运行 jar 外部不会触发,除非它与包含 Logo 文件的文件夹图像位于同一目录中。
所以我的问题是如何将图像打包到 .jar 文件中并让此代码引用它?