首先,请确保您的资源已正确加载(例如,使用System.out())!
而是
ImageIcon(String location)使用
ImageIcon(URLlocation)构造器,因为您的图像不在硬盘上,而是作为类路径中的URL动态压缩(例如MyJar.jar!/path/to/image.png“);您必须将图像加载方式修改为
this.getClass().getClassLoader().getResource("MyImage.png");
首先,请确保您的资源已正确加载(例如,使用System.out())!
而是
ImageIcon(String location)使用
ImageIcon(URLlocation)构造器,因为您的图像不在硬盘上,而是作为类路径中的URL动态压缩(例如MyJar.jar!/path/to/image.png“);您必须将图像加载方式修改为
this.getClass().getClassLoader().getResource("MyImage.png");