1

In Java documentation about TrayIcon's setImage method (http://docs.oracle.com/javase/7/docs/api/java/awt/TrayIcon.html#setImage(java.awt.Image) says:

If the image represents an animated image, it will be animated automatically.

But I can't get an animated image in the trayicon.

I've tested with PNG and GIF animated, 32x32, 64x64 and 128x128 combinations. But no one works.

Is there any specific format to thses animated tray icon images ?

FlamingMoe
  • 2,709
  • 5
  • 39
  • 64

2 Answers2

2

Check out the Swing tutorial on How to Use the System Tray.

I just changed the gif and it worked fine for me.

The gif I was using was 16x16. I also tried with a 137x116 gif and it worked, although I first had to right click on the "empty area" in the tray and then select the "Auto size" option.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Not in a Mac :-( it's weird ... each time I select the "Auto size" it appears still the frame it should appear ... so if I do very quickly I see still frames ... so the animation is "working" background and clicking the "Auto size" brings the "active" frame, but still. – FlamingMoe Dec 26 '14 at 17:59
  • Wow ! If i do a timer function where I execute "trayIcon.setImageAutoSize(true)" each 100ms, then I see the animation ... it's like you have to invoke the setImageAutoSize to see the current active "hidden" animation frame – FlamingMoe Dec 26 '14 at 18:16
0

Old question, but in case anyone needs this like me - you have to load the GIF image with new ImageIcon and not ImageIO.read.

trayImage = ImageIO.read(getClass().getClassLoader().getResource("logo.gif")); // DOESN'T WORK
trayImage = new ImageIcon(getClass().getClassLoader().getResource("logo.gif")).getImage(); // WORKS
Branislav Kuliha
  • 149
  • 2
  • 10