0
ImageIcon programIcon = new ImageIcon("/images/icon.png");
userRatingsPanel.setIconImage(programIcon.getImage());

That's my current code (and jframe too obv)

I'm trying to change the default icon

enter image description here

thanks!

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34
  • Use [`JFrame#setIconImages`](https://docs.oracle.com/javase/8/docs/api/java/awt/Window.html#setIconImages-java.util.List-) instead - as demonstrated [here](http://stackoverflow.com/questions/6403821/how-to-add-an-image-to-a-jframe-title-bar/6403846#6403846) – MadProgrammer Apr 21 '17 at 01:50
  • huhhh so do i need to make a new method for it? – PuppyLover101 Apr 21 '17 at 01:53
  • No, the mean already exists, but it tasks a list of images which allows the OS to pick the best one to use in a number of different situations, rather than having to up/down scale a single icon (I'd also make sure that the image is actually been loaded) – MadProgrammer Apr 21 '17 at 01:54
  • Sorry, im really new to Java. This is actually for a project I have to do for school. I have the icon image stored in a "images" folder. It's named icon.png – PuppyLover101 Apr 21 '17 at 01:56
  • What I mean is that I wanna make THAT icon show up in the windows taskbar and in the top left of the program – PuppyLover101 Apr 21 '17 at 01:56
  • Try adding something like `JOptionPane.showMessageDialog(null, programIcon);` after you've loaded the image, see if the image is displayed in the resulting dialog, if it is, then it's been loaded correctly, if not, you have another issue to resolve – MadProgrammer Apr 21 '17 at 01:57
  • Huh? :O It's currently like this http://i.imgur.com/sNACRr2.png – PuppyLover101 Apr 21 '17 at 01:59
  • Nono I want http://i.imgur.com/pdpTxow.png and http://i.imgur.com/nV5LRvT.png replaced by the icon :) – PuppyLover101 Apr 21 '17 at 02:00
  • Okay, sorry, running about termanology :P - Use `setIconImages` can support that functionality, but you may need to supply multiple images at different size, take a look at the [**example I linked earlier**](https://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html) – MadProgrammer Apr 21 '17 at 02:01
  • Uhh i dont want it in the system traayyyyy :P I want it as the icon (top left of the window and the general icon in the bottom (instead of coffee one) – PuppyLover101 Apr 21 '17 at 02:04
  • Yes - two things. 1- Make sure that the original image is been loaded; 2- use `setIconImages` instead of `setIconImage` - see [**linked example**](http://stackoverflow.com/questions/6403821/how-to-add-an-image-to-a-jframe-title-bar/6403846#6403846) (I sware my copy/paste functionality isn't working :P) – MadProgrammer Apr 21 '17 at 02:07
  • Ok I got it... Thanks! – PuppyLover101 Apr 21 '17 at 02:10

1 Answers1

0

You Can change your Icon

setIconImage(Toolkit.getDefaultToolkit().getImage(YourFrame.class.getResource("Your Source")));
Ahmad
  • 770
  • 9
  • 21