I've been playing around with a few image sizes for my Frame's icon.
The frame title bar icon in IE and Mozilla seems to take up 20x20 pixels of space, and I have ended up making my image (a gif) 20x20 also. If I make my image any larger, it gets distorted as it is shrunk to fit into the title bar.
So I use 20x20 for the image size, but the problem is when I do Alt+Tab my image appears magnified and looks poor.
Does anyone know what image dimensions I should use so it looks good in the Frame title bar and when Alt+Tabbing.
I've had this exact problem, and it's been driving me mad for months! It's made particularly bad because I have a round icon, and the transparency looks awful when the image is scaled.
I've asked about 3 different questions here on the same issue, and the few answers that I've had have been pretty much of the "can't be done" type. I'm coming to the conclusion that that's the right answer!
The only way of doing this properly that I've found is by using a Shell in SWT, but that can't be (easily) combined with the Swing/AWT stuff that I'm using in the rest of my application. (Shell does it very well though, by taking an array of Images, of different sizes, and using the most appropriate one).
Interestingly, if you don't set the icon, you get the default Javacoffee cup icon, which works properly! I've found one mention of a registry hack to change that icon to any Windows .ico file (which contains several icons of different sizes, for just this reason), but couldn't make it work, and it's far from being an ideal solution anyway.
If you do get anywhere on this, please, please post your solution here!
In the meantime, we're switching to a square icon!
Edit: I forgot to mention, you should also check your icon with Windows (if you're using Windows) set to 'Large Fonts', it makes the icon on the taskbar about 150% of its original size, and therefore has similar nasty effects! [ October 13, 2006: Message edited by: David Payne ]
How soon will you be able to migrate to Java SE 6 when it comes out? java.awt.Window has a setIconImages(List<Image> icons) so you might balance the level of effort you put into this versus how soon you can use Java SE 6.
For Windows 'Large Fonts' problem, maybe the Frame API contains methods that can be used to work out the height of the title bar. If so, they could be used to determine which image is used as the icon...
Originally posted by Tim LeMaster: How soon will you be able to migrate to Java SE 6 when it comes out? java.awt.Window has a setIconImages(List<Image> icons) so you might balance the level of effort you put into this versus how soon you can use Java SE 6.
Great, thanks Tim - that's actually a not-bad good solution for us. Shame it's no help for James...
James - interested to hear how far you got with the idea of calculating the size of the titlebar - sounds like something a bit too tricky for me to start playing around with 10 days before release...
Using Frame's getInsets(), I've come up with the following method which works well. Basically, the method finds the title bar height and (after much experimenting by my good self!) uses an appropriately-calculated image size to use as the icon image.
I should stress that I've only tested this on the appearance settings that come with Windows XP, so this method might well need expanding for title bar height / icon image sizes for other systems. (If anyone does expand it, please post the expanded method back here.)
At the moment, the only problem with the method is that the 'Windows Classic Style with Extra Large Fonts' appearance needs an icon image of 28x28 - and that appearance has the same Insets values as the 'Windows Classic Style with Large Fonts' appearance. And as I don't know how to discern between these two appearances in my code then the 'Windows Classic Style with Extra Large Fonts' has to use the 20x20 icon instead of the preferred 28x28. Any ideas anyone?
Just out of curiosity, does the window already have to be visible, or just layed out, or can you run that method at any time?
I'll see what happens with our square icon, when I get it, but might well borrow your code, if that's OK.
It's so nice to know that it's annoying someone else as much me - I was beginning to think that I was crazy.
An interesting(ish) aside: if you print from your application, you'll notice that the icon in the taskbar for the print and page setup dialogues actually comes from the Windows application icon (which gets set as an .ico by our installer), and that works correctly.