【发布时间】:2014-02-12 19:58:20
【问题描述】:
我正在尝试将图像设置为 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 之外不会触发,除非它与包含徽标文件的文件夹 images 位于同一目录中。
所以我的问题是如何将图像打包到 .jar 文件中并让这段代码引用它?
【问题讨论】:
标签: java image swing embedded-resource