wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Frame's setIconImage() - optimum image size for title bar & Alt+Tabbing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frame Watch "Frame New topic
Author

Frame's setIconImage() - optimum image size for title bar & Alt+Tabbing?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
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.

Cheers,
James
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Hi James,

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 Java coffee 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!

David.

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 ]
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
David,

Thanks for the reply.

Less thanks for the 'Large Icon' tip - I could more or less live with things until you said about that!...

Looks like I might have to go the square route as well...

It's a bit of shame - you spend so long getting a GUI to look right, and you end up with a weak link like this.

Cheers for the suggestions. I'll post whatever best solution works for me anyway.

Cheers,
James
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
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.

Good luck!
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya Tim,

Not for quite a while, I'm afraid - our applet has to be in Java 1.1...
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
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...
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
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.

Good luck!


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...
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
David,

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?

Cheers,
James
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
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.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
David,

Yes, you can use the code, no probs.

According to Container's javadocs, the frame.getInsets() call will only return correct values after pack() or show() is called on frame.

I call the setFrameIconImage(frame, ...) method immediately after calling frame.show(). I haven't really experimented with calling the method at other times.

Yes, it's surprising how little has been set about this icon problem. I was wondering if there was something obvious I was missing, but seemingly not.

Cheers,
James
 
wood burning stoves
 
subject: Frame's setIconImage() - optimum image size for title bar & Alt+Tabbing?
 
Similar Threads
Nice Round Title Bar Icons?
System Tray icon for the Swings application
where to find in api
Size of frame problem /XP
and onto graphics