How to set an icon to a JFrame when using createAndShowGUI() method?

北城余情 提交于 2019-11-29 15:12:47

When I run the above code with a test image, the icon is changed correctly. Add:

System.out.println(System.getProperty("user.dir"));

to the method to display the folder where the image should be located & copy it there if necessary.

Why don't you make package like:

org.icon 

and add icons to that package.

To set icon use this:

ImageIcon img = new ImageIcon(Game.class.getResource("/org/Icon/NameOfIcon.png"));
game.setIconImage(img.getImage());

You program will have no problems to find an icon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!