3

I've just realized that in different versions of Windows, and for different purposes, different sized icons are used. For example, the icon in the window title bar is much smaller than the program's task-bar icon, in Windows 7 especially.

I have found Which icon sizes should my Windows application's icon include? very useful list of icon sizes that are used by Windows but I don't know how to provide them so that Windows can select the size it needs for certain tasks.

I would appreciate any advice or help from anyone regarding the matter. I don't know how clear I have made myself, so if anyone wants me to clarify anything please don't hesitate to ask.

Also, if anybody knows if this applies to Mac or how I can adapt it my code to make it apply to OS X please could you tell me that as well.

UPDATE: This is for my Java Swing application

Community
  • 1
  • 1
Andy
  • 3,600
  • 12
  • 53
  • 84

2 Answers2

10

See Window.setIconImages(List). Depending on the platform capabilities one of several images of different dimensions might be used as the window's icon. There is an example on the File Browser GUI thread. This image shows the small icon used for the GUI, the larger one is seen when alt-tabbing between windows.

If the image is not square, Windows will pad it.

Java Web Start provides similar options for multiple sizes of icon for use in desktop shortcuts & menu items.


Re: images named:

  1. fb-icon-16x16.png fm-icon-16x16.png
  2. fb-icon-32x32.png fm-icon-32x32.png

..it doesn't matter on file names or anything - windows just picks the icons based on the image size?

Yes, the file names were chosen to include the size information for the benefit of developers. We might call the images:

  • icon-small.png
  • icon-medium.png

.. and it will work the same. The JRE will base the choice on the actual size of the image as measured once loaded. However I highly recommend adding something like -16x16 to a icon image names to make it explicit. The size of 'a small icon' changes over time & across devices.

what happens when you don't provide multiple sizes?

The JRE or system will scale the one image according to an algorithm that is not within the control of the developer. For example as above.

If the image is not rectangular, Windows will pad it.

I have a DukeBox player that attempts to pick up track or album art that applies to the track that is playing. It not only displays the image over the top of the sound trace, but also sets it as the (single) frame icon. Windows (at least) will scale to size, and pad with transparency for any non-square image. Windows even handles a PNG with partial transparency with aplomb.

OTOH, AFAIU OS X does not display frame icons. By design decision. I do not know if that results in the icon not appearing at all. You'd need the advice of a Mac. guru for better info. on that.

Since systems make their own (not necessarily optimal) decisions on how to scale icons, it is best to take as few chances as possible, & attempt to provide the right sized icon(s) for each platform. You're in luck if they have a common size or 3.

See also: the Sizes of frame icons used in Swing Q&A.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Thanks for that Andrew. As always, a brilliant answer and nice example. Just to be sure, it doesn't matter on file names or anything - windows just picks the icons based on the image size? – Andy May 12 '12 at 16:16
  • Yes, the file names were chosen to include the size information for the benefit of **developers.** We might call the images `icon-small.png`, `icon-medium.png`.. and it will work the same. The JRE will base the choice on the actual size of the image as measured once loaded. However I highly recommend adding something like `-16x16` to a icon image names to make it explicit. The size of 'a small icon' changes over time & across devices. ;) – Andrew Thompson May 12 '12 at 16:19
  • Thanks for confirming that. I was going to include the size in the file name for my benefit anyway but I was just checking. Just of of curiosity, what happens when you don't provide multiple sizes? – Andy May 12 '12 at 16:21
2

If you use the SWT to develop a java application, you can set a image array on the shell.

user1112699
  • 197
  • 3
  • What format, order, and/or names do the images have to be in. And what do you mean by "on the shell" – Andy May 12 '12 at 16:04
  • You look like using the swing to develop java application. Please use the API: Window.setIconImages(List) – user1112699 May 12 '12 at 16:08
  • Yeah. Sorry I didn't include it that detail in my question. I am using Swing. Andrew Thompson's answer is helping my right now but thanks a lot for yours. – Andy May 12 '12 at 16:19