February 18, 2007 6 Comments
While diving into Xebece hacking I got an interesting idea for Swing. One major complaint against Swing apps is that they look very alien on most desktops. With newer JDK releases you can improve the situation a lot by using the native L&F of your platform, at least on Windows, GTK and MacOS X. The L&Fs are pretty good overall, by far not perfect but OK-ish. Except for the icons…
One thing that lets Swing applications still stand out very much is the integration (or lack of) of the native icon theme. For an application developer it is more or less impossible to integrate the standard toolbar and menu icons for things like File->Open, File->Exit etc. For example, in Gnome a theme usually also provides an icon theme for a whole bunch of stock icons. It would be nice to have a way to access these icons without doing lots of platform specific code in your application. One possible solution could look like this:
- A defined set standard icons would be available via the LookAndFeel’s UIDefaults.getIcon(String) method.
- The keys to access these icons would have to be documented and L&F implementations should provide these icons whenever possible.
- Icons should be available for menus and toolbars at least. It might make sense to provide icons for a couple of fixed sizes too (as Gnome does).
- There would have to be a sane naming scheme for the keys. For example, icon.file.open.16 for a 16×16 file-open icon. Or icon.file.open.toolbar for a file-open icon suitable for a toolbar.
- L&F Implementations should use the native icon theme when possible, rather than using a fixed / built-in icon. For example, the GTK L&F implementation should use gtk_icon_theme_lookup_icon() to lookup the current theme’s standard icons.
- The built-in actions (for example, the actions provided by the text EditorKits) could provide corresponding standard icons too.
Overall I think this shouldn’t be too hard to implement, and it would allow Swing applications to blend much better into the user’s desktop, without the need of lots of platform specific code in the application.