Add images to jar

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

    For this to work, you should access the images from a directory relative to some fixed class. For example, if the image files are saved in a directory "images" on the same level as the Toolkit.class, then

    this.setIconImage(Toolkit.getDefaultToolkit().getImage(Toolkit.class.getResource("images/icon.jpg"))); should work.

提交回复
热议问题