Add images to jar

前端 未结 8 1442
孤独总比滥情好
孤独总比滥情好 2021-02-06 12:30

I want to set icon to my JFrame. I do the following:

Image icon = Toolkit.getDefaultToolkit().getImage(\"src/images/icon.jpg\");
this.setIconImage(icon);
         


        
8条回答
  •  遇见更好的自我
    2021-02-06 12:37

    .."/src/images/icon.jpg"..  
    

    The '/src' prefix of the address seems suspicious. Many apps. will provide separate 'src' and 'build' directories, but it normally ends up that the 'src' prefix is not used in the resulting Jar. I recommend trying..

    .."/images/icon.jpg".. 
    

    & also triple checking that the image is in the location of the Jar that the code is expecting to find it.

提交回复
热议问题