一开始 图片的加载路径是 new ImageIcon("./imageX.png")格式,在Jar中如果用这种方式加载是不行的,
换成下面
Icon runImg = new ImageIcon(this.getClass().getClassLoader().getResource("image/run.png"));
这时候的image包要放在src下
本文介绍了在Java项目中,如何正确地从jar包内加载图片资源。通过使用类加载器获取资源路径的方法解决了直接文件路径加载的问题。
一开始 图片的加载路径是 new ImageIcon("./imageX.png")格式,在Jar中如果用这种方式加载是不行的,
换成下面
Icon runImg = new ImageIcon(this.getClass().getClassLoader().getResource("image/run.png"));
这时候的image包要放在src下

被折叠的 条评论
为什么被折叠?