Add images to jar

前端 未结 8 1569
孤独总比滥情好
孤独总比滥情好 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:42

    getResource() loads a resource from classpath, not an OS path, and the after compilation your classpath will not include the /src folder, but rather just its contents. So you'd better try /images/icon.jpg.

    Also you may find this discussion somewhat useful.

提交回复
热议问题