Displaying an ImageIcon

后端 未结 2 1664
面向向阳花
面向向阳花 2020-12-11 23:39

I am trying to display an image on a JPanel. I\'m using an ImageIcon for rendering the image, and the image is in the same directory as the class f

2条回答
  •  半阙折子戏
    2020-12-12 00:19

    You should use

    ImageIcon image = new ImageIcon(this.getClass()
                    .getResource("org/myproject/mypackage/peanut.jpg"));
    

提交回复
热议问题