Java TrayIcon image to be animated - java

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 ?

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.

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

Related

Stop a looping GIF icon

I am using an animated GIF image as icon to button.
But this GIF loops without stopping.
How can I play this GIF icon animation just once?
When creating an animated GIF, there are options to have it only loop a single time. That is where you need to look for a solution to this problem. Swing itself provides no methodology to change the behavior.

Animated GIF as an icon for notification

Is it possible to set an animated GIF as an icon for Notification? I know that I can split it into a set of static images and then use animation-list but splitting is a hard work for complex animation.
Is it possible to set an animated GIF as an icon for Notification?
Yes. However, it will not animate.

Rotate GIF images in java

I am trying to rotate a GIF image in java.
I read these interresting two trails about rotating images in java : trail 1 , trail 2.
All works fine, except that when I rotate my GIF image, there is no more animation of the GIF image. Only the first image of the GIF animation is displayed.
So, is there any way to keep the GIF animation after rotating my GIF image, without using any third part library but only standard J2SE?
Or will I be obliged to separate my GIF image into single images, rotate them one by one, and then display them in a loop?
I don't give any piece of code I wrote because it is not relevant in my humble opinion.
I think animated gifs work by storing multiple frames, all in the gif format.
So you just need to apply you rotation method to every single image, instead of the whole gif.
Wikipedia has a quite nice description of the format

Modifying taskbar icon of my .jar program

I'm trying to change the default java icon that appears in taskbar everytime I run my .jar program. I managed to change it with frame.setIconImage(img); but this makes icon way too small, I want it to be as big as other programs icons and have a high quality. Any way I can do that? Thanks.
As you only supplied a single icon, Windows will then scale that icon to whatever size it needs displaying it in the taskbar (could be 16x16, 32x32 or other sizes, depending on the desktop them and size of the taskbar.
If you want to have a "good looking" icon in the task bar you will need to provide a 32x32 pixel version of your icon.
Once you have that you can call setIconImages(List) instead of setIconImage() to define the icons that the operating system can use:
List<Image> icons = new ArrayList<Image>();
icons.add(getImage("someImage16x16.gif"));
icons.add(getImage("someImage32x32.gif"));
window.setIconImages(icons);
Where getImage() is some method returning the proper image icon. Essentially that would be the same steps you already used to define the current icon.
You can also supply a 64x64 and 24x24 icon using this method (just add more icons to the list).
Try looking at this example. It looks like you need to use frame.setIconImage(Toolkit.getDefaultToolkit().getImage("your_image.gif")); line

PNG TrayIcon transparency on Windows

I'm trying to use a transparent PNG as the icon for my Java application. The image on the JFrame and task bar work great. However, when I use the image with a TrayIcon, I get a black matte background around the edge of the PNG.
Has anybody else come across this issue? I would really like to use a PNG instead of GIF or JPEG.
With Java6, a PNG picture should be used for TrayIcon, but as mentioned in this SO question, check:
the background color chosen to represent the transparent pixels
the transparency options
the resolution of the icon
alternate format like SVG (provided you are using external library like Batik, and conversion mechnism to java.awt.Image)

Categories