ImageIcons on JButton are not showing up in Runnable JAR file

空扰寡人 提交于 2019-11-29 11:07:39

This (as pointed out by a number of people)

ImageIcon SettingsIc = new ImageIcon("bin/images/settings.png");

Suggests that you are trying to load the images from the bin/images off the file systems. This is a relative path from the execution point of your application.

ImageIcon won't complain if the file does not exist.

If possible, you are better off embedding the resources within your Jar file (it will make it easier to deploy) and use something like getClass().getResource("/bin/images/settings.png") to load the images.

If possible, you should try using ImageIO.read(URL) to load your images, it will throw an exception if the resource pointed to by the File/URL does not exist (or is invalid).

ashwin

Just keep the jar and images in the same folder and keep

ImageIcon icon = new ImageIcon("image.jpg");

in the code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!