3

I am trying to set up icon for my java swing application with this code

setIconImage(new ImageIcon("logo.png").getImage());

but it is showing error on ImageIcon as cannot find symbol. Can anyone help me with a solution?

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Suresh
  • 501
  • 1
  • 5
  • 11

2 Answers2

4

Put the logo.png file in the same package as the class that's calling it

ProjectRoot
         src
             MyClass.java
             logo.png

and use

ImageIcon icon = new ImageIcon(getClass().getResource("logo.png"));
setIconImage(icon.getImage());

See Load Image icon Exception for more details

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
1

try this :

setIconImage(new ImageIcon(Main.class.getResource("logo.png").getPath()).getImage());

in this example Main is name of your class

Vahid Forghani
  • 343
  • 1
  • 2
  • 14