Sizes of Frame Icons Used in Swing

Sizes of frame icons used in Swing

Typical views for this Windows 7 based PC

Note: @bobbel reports the same sizes are used for Windows 10.

Frame - 20x20

Icon Size Usage - showing 20x20 frame icon

Task Bar - 40x40 in task bar itself, hover app shows 20x20

Icon Size Usage - Task Bar

Windows+Tab - 20x20

Icon Size Usage - Windows+Tab

Alt+Tab - 40x40 in lower right, shrunken 20x20 in upper left.

Icon Size Usage - Alt+Tab

Task Manager - 20x20

Icon Size Usage - Task Manager

How to customize the size of frame Icon image?

The frame icon image size can't be changed. If you need something really custom you will to create your own decorations for a window, but that is not as simple as just changing the size of an icon.

Which icon sizes to use with a JFrame's setIconImages() method?

According to the API the runtime chooses the most appropriate size to use from the list supplied. I would supply 16x16, 32x32, 64x64 and 128x128 and let the JVM decide at runtime.

public void setIconImages(List<? extendsImage> icons)

Sets the sequence of images to be displayed as the icon for this window. Subsequent calls to getIconImages will always return a copy of the icons list.

Depending on the platform capabilities one or several images of different dimensions will be used as the window's icon.

The icons list is scanned for the images of most appropriate dimensions from the beginning. If the list contains several images of the same size, the first will be used.

Ownerless windows with no icon specified use platfrom-default icon. The icon of an owned window may be inherited from the owner unless explicitly overridden. Setting the icon to null or empty list restores the default behavior.

Note : Native windowing systems may use different images of differing dimensions to represent a window, depending on the context (e.g. window decoration, window list, taskbar, etc.). They could also use just a single image for all contexts or no image at all.

Parameters:

     icons - the list of icon images to be displayed.

Since:

     1.6

See Also:

     getIconImages(), setIconImage(Image)

How to customize the icon in the window title using Swing?

You can use the method setIcon(Icon icon) and the icon will be displayed near the label.

public void setIcon(Icon icon) Defines the icon this component will
display. If the value of icon is null, nothing is displayed. The
default value of this property is null.

This is a JavaBeans bound property.

How to change the size of JFrame icon

Frame icons are set according to a size decided by the OS.

  • If you supply icons of various sizes, Windows will use the smaller one for the frame icon, and the larger one as the image to include in the window shown when the user types alt tab to change between apps.
  • OS X shows no frame icon at all.

See also: Sizes of frame icons used in Swing.

Use different icons in JFrame and Windows taskbar

I cound not use the suggested solutions because I have jdk 1.5 as requirement ...

So, I did this:

public void setAppIcons(JFrame frame) {
List<Image> images = new ArrayList<Image>();
images.add(getImage(MessageUtils.getString("application.images.icon.app.32")).getImage());
images.add(getImage(MessageUtils.getString("application.images.icon.app.16")).getImage());

try {
Class<?> [] types = {java.util.List.class};
Method method = Class.forName("java.awt.Window").getDeclaredMethod("setIconImages", types);

Object [] parameters = {images};
method.invoke(frame, parameters);
} catch (Exception e) {
frame.setIconImage(images.get(0));
}
}

If the client is running the application in a jre 1.6 or major, the application will pick the image list to set ...

Tks for your suggestions.

Different icon sizes for the OS in Java

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.



Related Topics



Leave a reply



Submit