Posted by ixmal
on June 16, 2006 at 6:37 AM PDT
Prior to Mustang developers could specify a single icon image for every Java frame. This image was then displayed in the frame's titlebar, in the system taskbar and other places. However, some of that places require images of different size, and this made the specified image be scaled so it looked very ugly. Now in Mustang you can set several images to represent frames' and dialogs' icons wherever it is required.
What's the problem?
In Java™ 2 SE 5.0 and previous releases a single method in
java.awt.Frame class enables developers to specify an icon for the frame:
setIconImage(Image image). This image had an arbitrary size and it was scaled to represent frame's icon in a different locations.
Let's assume that application is running on Windows platform. Icon that was set to the frame is used in several places: on the frame's title bar, on the button on the system taskbar, in the window list when switching to another application by pressing Alt-Tab. The taskbar icon usually has a 16x16 pixels size, the title bar icon size varies depending on the user settings, window list uses a 32x32 sized icons. Thus, if we specify an image of 16x16 pixels size, it will look fine in a taskbar and ugly when switching to another application. The 32x32 pixels image has the similiar problems.
In the Mustang release the following new method is introduced to the
setIconImages(List<? extends Image> icons). Using this method you can supply as many images as you need to represent window's icon.
How does it work? Every time either the system or window manager needs an icon for Java window, it examines the list of specified images and searches for the image of the most appropriate size. Exact definition for this 'most appropriate' size is platform-dependent.
You may have already noticed that the new method is added to the
java.awt.Window class, not to the
java.awt.Frame class. In particular, this fact means that you can now set an icon for Java dialogs as well as for frames. This feature is extremely important for parentless dialogs introduced in earlier Mustang builds.
If no icon is set for a dialog, it inherits the icon from its parent window. If a parent is
null - that means the dialog is parentless - the platform-default icon is used. If a parent is not-
null and no icon was explicitly set for the dialog, then the icon is inherited from the parent window.
When will this API be available?
The answer is: it is already available, since Mustang b85 build was released at the end of May. However, some minor improvements are planned for the next Mustang builds.