![swing set icon swing set icon](https://fscomps.fotosearch.com/compc/CSP/CSP467/swing-icons-set-outline-style-stock-illustration__k57531724.jpg)
My JPG loads fine in other image viewers, so that's ruled out as well. But I have now already exhausted my understanding of images and icons in the mighty, wide world of Swing. To create a JLabel with an image icon we can either pass an ImageIcon as a second parameter to the JLabel constructor or use the tIcon () method to set the icon. tIconImage () To set the icon to the window. (answered Aug 27 '13 at 0:18 AndyTechGuy) tIconImage (ImageIO.read (new File ('res/icon.png'))) Share. Following example showcase how to change the default icon of the window in Swing based application.
![swing set icon swing set icon](https://b4.3ddd.ru/media/cache/tuk_model_custom_filter_en/model_images/0000/0000/4305/4305046.62c14ceb06228.jpeg)
So that leaves me to believe there's something that getResource() doesn't like about the JPG itself. By Wayan in Swing Last modified: Decem5 Comments. Try putting your images in a separate folder outside of your src folder. I have subsequently placed the JPG in just about every directory inside my project, just to rule file location out as the culprit. I have used the (new File(".").getAbsolutePath()) trick to locate the directory where the image JPG should be stored, and still nothing worked. To me, there's only 2 possibilities here: (1) the myImage.jpg is in the wrong directory, or (2) getResource() doesn't like something about my image (I had to convert it from CMYK to RGB in Photoshop so I could use the same image elsewhere with ImageIO.) This code fails down in loadIcon when making a call to the getResource() method. Private ImageIcon loadIcon(String strPath) ImageIcon myAppImage = loadIcon("myimage.jpg") Here's "my" code (heavily borrowed from other posts and the internet at large): public class MyApp extends JFrame I've seen many different examples showing how to set a JFrame's IconImage so that the application uses that icon instead of the standard coffee mug.