[英]ClassLoader.getResource() doesn't work for the icon files in a jar. The icons need to be present in the folder containing jar
我正在使用圖標文件的Java程序。 圖標存儲在/src
中的文件夾Icons
中。 訪問圖標的代碼是
image1 = new ImageIcon(Control.PrimaryGameFrame.class.getClassLoader()。getResource(“ Icons / openFile.gif”));;
該程序可以在Eclipse中正常運行。 但是,當我將其可運行jar導出到文件夾abc
,它需要將Icons
文件夾存在於abc
。 如果我將罐子放在一個地方,它不會加載圖標。 要對代碼進行什么更改,以使jar本身而不是在其所在的文件夾中查找圖標文件?
嘗試這個:
ImageIcon image1 = new ImageIcon(getClass.getResource("Icons/openFile.gif");
這對我來說很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.