1

I want to be able to change the taskbar button image to a custom image instead of the default Java image.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

5

Use

ImageIcon img = new ImageIcon(PathToFile);
frame.setIconImage(img.getImage())

Keep in mind if you export it to a jar it will still have the Java coffee cup as its icon.

You can also use Window#setIconImages which allows you to supply a variety of image sizes which allows the native windowing system to decide which one it would like to use (Thanks MadProgrammer)

GreySwordz
  • 368
  • 1
  • 9
  • 2
    You can also use [`Window#setIconImages`](http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setIconImages(java.util.List)) which allows you to supply a variety of image sizes which allows the native windowing system to decide which one it would like to use...makes it look nicer ;) – MadProgrammer Feb 20 '14 at 01:59
  • @MadProgrammer nice one i didn't know about that – nachokk Feb 20 '14 at 02:12
  • @MadProgrammer Good point. See also [Sizes of frame icons used in Swing](http://stackoverflow.com/q/18224184/418556) & the answer of [mKorbel](http://stackoverflow.com/a/18225431/418556) for a summary of preferred sizes for two Windows set-ups. – Andrew Thompson Feb 20 '14 at 02:34
  • @peeskillet Raise a separate answer so I can upvote it ;) – MadProgrammer Feb 20 '14 at 02:34