The Source for Java Technology Collaboration
User: Password:



Artem Ananiev

Artem Ananiev's Blog

Improved top-level icons support in Mustang

Posted by ixmal on June 16, 2006 at 06:37 AM | Comments (9)

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.

More icons


In the Mustang release the following new method is introduced to the java.awt.Window class: 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.

Dialogs icons


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.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Im going to have to try this out. I guess my question is, what happens if it finds not just one, but many suitable Icons to use. Does it just grab the first one? Anyway, this sounds like a good feature.

    leouser

    Posted by: leouser on June 16, 2006 at 07:16 AM

  • Great. Thanks! I've been waiting a long time for this feature. Works perfect. Seems that Mustang now also supports PNGs with alpha-channel for window icons :)

    Posted by: ktauber on June 16, 2006 at 04:09 PM

  • Any intention to accept .ico format (with different resolution images)?

    Posted by: montechristos on June 17, 2006 at 04:49 AM

  • To leouser: if several suitable images are found in the list, the first one will be used, you're right

    Posted by: ixmal on June 19, 2006 at 03:57 AM

  • To montechristos: ICO format is not supported by Java2D yet

    Posted by: ixmal on June 19, 2006 at 04:08 AM


  • Hi brian,
    the first image that match is used.
    see
    http://download.java.net/jdk6/docs/api/java/awt/Window.html#setIconImages(java.util.List)

    Rémi Forax

    Posted by: forax on June 19, 2006 at 12:30 PM

  • Huray!

    It took Sun just TEN years to finally get their act together. Ten years. Oh, in the mean time the Swing team wasted time to implement the practically undocumented synth PLAF, presented one shiny demo (without surce code) after the other at JavaOne, implemented ICC profile handling, JAI, two or three more broken printing systems, or had fun rewriting AWT on top of Swing.
    But non of these heros could be arsed for ten years to fix that bug.
    Thanks for nothing, Sun!

    Posted by: ewin on June 19, 2006 at 02:06 PM

  • This support should be added to java.awt.TrayIcon for the same reasons!
    - TrayIcon(Image)
    - setImage(Image)
    should be complemented with
    - TrayIcon(List)
    - setImages(List)

    Posted by: rivasdiaz on June 19, 2006 at 04:47 PM

  • Sounds great, well took long time for that feature. I hope the .png file will render as mentioned.

    Posted by: mac_systems on June 19, 2006 at 11:50 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds