Skip to main content

Hi-Fi Swing (or improving the native fidelity of Swing System L&Fs)

Posted by bino_george on November 29, 2004 at 5:07 PM PST


Hi-Fi Swing (or improving the native fidelity of Swing System L&Fs)

One of the biggest strengths of Swing is the lack of a rigid coupling
between the underlying platform toolkit and the Swing API. The Swing
API was designed to be extensible and free from platform limitations.
Other Java based GUI Toolkits have taken a different approach that
is more closely bound to the platform toolkit. As always in life
there are two sides to every story. The freedom from platform
restrictions comes at some cost in terms of engineering the Swing
Toolkit. Swing engineers have to make conscious trade-offs between
native fidelity and platform independence. Over the years our
users have requested that we provide the absolute best fidelity
for our System Look and Feels. There is a nice list of custom
L&Fs here : http://www.javootoo.com

Window blinds and Windows theming

Theming the Windows desktop has been very popular for many years.
PC System Manufacturers like Sony or Gateway have shipped custom
Windows themes to provide a branded look that identifies the desktop
with the system manufacturer. Personally, I have always found this
to be quite annoying and have tried to disable such customizations.
I just want to have a standard Windows Desktop!
But, there are many users who like the power and flexibility of
customizing their desktop to look like their favorite TV show or
whatever. One of the favorite Themeing applications for Windows
is called
WindowBlinds

UxTheme API

WindowBlinds and other such theming engines have traditionally used
the Windows system-wide Paint hooking facilities to customize the
rendering of standard windows controls. As you can imagine this
is not a trivial thing to get right and there are lots of pitfalls.
Window blinds was so popular in its functionality that Microsoft
worked with the author of this product to develop a new API that
exposes the rendering of Windows controls. This API is called

UxTheme
.
Windows XP provides a new Look and Feel (the default XP L&F) based on UxTheme API that users
can extend using the UxTheme API.

Longhorn

In Tiger and Mantis, we have provided support for the Windows XP
look and feel. The mechanism used to provide this support
was based on reading the resources embedded in the XP styles
files and using those icons and colors to render our Windows Look and Feel. Unfortunately, Microsoft has changed the
Styles files in Longhorn so that the resources are no longer
visible using the mechanism we used in Tiger and Mantis. So naturally
when we ran the current JDK under Longhorn we fell back to the
Windows classic Look and Feel used in Windows 2000. Swing will
fall back to this Look and Feel if it cannot load the XP L&F
for some reason. This is not a desirable situation, we want the
best user experience for our Longhorn users when Longhorn comes
out. We wanted to make sure that the Longhorn themes work
well in Swing apps.

Implementing a Hi-Fi Windows Look and Feel

We talked this over with engineers from Microsoft's graphics team, they
suggested that the way to work with the Longhorn themes was to
use the UxTheme API. So Leif Samuelsson (Swing Windows Look and Feel Author)
and I prototyped a version of the Windows XP Look and Feel that uses the
UxTheme engine to perform the rendering of Swing components. We then tested the
prototype under Longhorn and found that indeed the rendering of
Longhorn theme was pixel perfect with UxTheme. This lead us to
the re-implementation of the Windows Look and Feel using UxTheme.
This new implementation should be available in the latest Mustang build.
Check it out and let us know how it works and especially file
any bugs you find.

Implementing a Hi-Fi GTK (Linux) Look and Feel

So far I have focused on Windows. But dont think that we do not care about
Linux. We are currently working on improving our GTK fidelity based on
a similar approach. GTK provides the
GTK styles API
to hook into the GTK native rendering.
We are looking into how best to use this API to improve the GTK rendering
for Swing Apps.

Mustang

Mustang is the code name for the Java 6.0 project. Now that the Mustang builds are publicly posted, you can try out the
latest fixes and improvements and give us feedback on the builds and
the source. Please let us know what you think about Mustang at the Mustang project forum.

Bino George,
Staff Engineer, Swing/JDNC team.


Related Topics >>