Add images to jar

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

    You can simply create a package inside the main source, and incluse your images in this package. Then, just call the images in your main class like:

    ImageIcon a = new ImageIcon(MainClass.class.getResource("/Package/Image.jpg"));

提交回复
热议问题