Search code examples
javaurliconsimageicon

How to make an icon URL based, Java


I've made an Java app that uses URL based images instead of file based images. My question is, is there a way to get a URL image into an icon image?

frame.setIconImage(new ImageIcon("icon.png").getImage());

That's how i would usually do an icon image but i tried:

frame.setIconImage(new ImageIcon("i.imgur.com/<whatever>").getImage());

and it didn't seem to work, so is there a way to to it or is there atleast a way to get rid of the icon altogether without using a blank texture file?


Solution

  • URL url = new URL("http://some url/mypic.jpg");
    Image image = ImageIO.read(url);
    
    f.setIconImage(new ImageIcon(image).getImage());