Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a icon for the java swing applciation?

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?

like image 771
Suresh Avatar asked Mar 04 '26 04:03

Suresh


1 Answers

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

like image 79
Paul Samsotha Avatar answered Mar 05 '26 17:03

Paul Samsotha