Add images to jar

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

    Assuming your JAR file has a top level directory called images, you can use either:

    1. getClass().getResource("/images/icon.jpg") or
    2. getClass().getClassLoader().getResource("images/icon.jpg")

提交回复
热议问题