简体   繁体   中英

Different icon sizes for the OS in Java

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

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-图标16x16.png
  2. fb-icon-32x32.png FM-图标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.

如果使用SWT开发Java应用程序,则可以在shell上设置图像数组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM