Skip navigation.

Java and GTK+ integration

Sun Microsystems
Sun Microsystems

After I mentioned the planed Java GTK+ integration in the last GNOME Summary people have been asking me for more details on the Java GTK+ themeing. So I decided to contact Sun's Scott Violet who is the technical lead for Swing, and who are part of the group that architected and implemented Swing's GTK+ look and feel. HE was kind enough to answer some questions, so here is my small Java and GTK+ interview to satisfy the curios among you :)
So read the interview below.
ChristianJava 1.4.2 will feature support for GTK+ themes, do this include all theme engines or just a subset?

Scott: Only a subset. The GTK+ look is emulated, so there is a need to port engines over. 1.4.2 will include pixmap, bluecurve and the default.

So how will user get their Java apps to look like their GTK+ apps?

Scott: Just as any other swing look and feel, you can do:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndfeel");
And your Swing app will look like a GTK+ app.


Since only a subset of the theme engines will be available, will it be possible for theme engine developers to do create their own java theme engines to match their GTK+ engine?

Scott: We really scrambled to get a GTK+ look in 1.4.2, as such we didn't have time to open up as much of the API as we would have liked. In other words creating your own theme engine in 1.4.2 won't be possible. In 1.5 we will open up the API to allow creating your own theme engine, just as you can in GTK+. The API will be very similar to that of GTK+, so that it will be trivial for a GTK+ theme engine developer to write the equivalent Swing GTK+ theme engine.

Any other GTK+ and GNOME integration features?

Scott: For internal frames we provided support for mapping the look to metacity themes. In 1.4.2 we hardcoded crux and bluecurve, but in 1.5 we will support parsing metacity theme files so that we should be able to emulate any metacity theme.


When can we expect Java 1.4.2 to be available?

Scott: A beta should be out really soon!

Screenshots

Scott where kind enough to provide us with some screenshots showing the GTK+ style themes in action.

Re: Java and GTK+ integration

As far as I understand this, here goes:

- The AWT is a basic toolkit to get Java and Java applications "up and running" on any system. The AWT is usually implemented as system-native code, providing a "virtual", portable API layer for apps. The native nature has the advantage of being integrated within the system, but the disadvantage of not easily being extensible from within the language.

- Swing is a more extensible toolkit, largely written in Java itself to make it easier to extend and modify. The "problem" with Swing is that it's on its own for its look and feel, resulting in those easily recognizable freaky so-called "metal" looking Java apps.

OK, if some of the above is wrong, tell me.

Anyway, in order to integrate Swing with the underlying system (being it with or without system themes), you need native code: to check out what system you're on, and, in case of themes, what it looks like outside. This should mean that for every Swing component, some native code actually defines the shape of the component.

If that's true, then why doesn't Swing just totally move towards an implementation on top of a native toolkit?

I guess the reason is that Swing should be portable, because it may not be part of every VM installation and thus may need to be shipped with (cross-platform) products?

Anyway, I'd like to know.

Greets,

Pflipp