Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Magic with Merlin: J2SE 1.4.2 gets two new look-and-feel designs

GTK+ and Windows XP join Windows Classic, Motif, and Metal

John Zukowski (jaz@zukowski.net), President, JZ Ventures, Inc.
Author photo
John Zukowski conducts strategic Java consulting with JZ Ventures, Inc. and serves as the resident guru for a number of jGuru's community-driven Java FAQs. His latest books are Java Collections and Definitive Guide to Swing for Java 2 (second edition) from Apress. Contact John at jaz@zukowski.net.

Summary:  In an attempt to keep up with the latest and greatest in user desktops, Sun has updated the standard set of look-and-feel designs provided with the J2SE 1.4 platform. In this installment of Magic with Merlin, John Zukowski uses the latest 1.4.2 release (in beta at the time of this writing) to show Windows users how to get the newer look of Windows XP, as well as the GTK+ look typical of a Linux desktop.

View more content in this series

Date:  27 May 2003
Level:  Introductory
Also available in:   Japanese

Activity:  7849 views
Comments:  

While all of the Magic with Merlin columns have so far been about features new to the Java 1.4 release, this latest column is specific to the 1.4.2 version, now in beta. Sun has decided that the Windows classic look has grown old and nobody uses Motif anymore -- at least on the typical user desktop. What you'll find in this latest version of the standard Java platform is an updated Windows look and feel that looks like Windows XP when the user is on a Windows XP box, and a completely new look and feel called GTK+, which has the look and feel of a common Linux desktop.

The Swing architecture provides a pluggable look-and-feel framework. The framework offers a standard way, for instance, to make the font of all components 8-point bold Lucida, without having to change every call to create a component. You just plug in a new setting in the look and feel and magically everything picks up the changes. You can even change the overall style of the GUIs by setting the look and feel. Previously, J2SE 1.4 offered look-and-feel designs for platform-specific UIs like Microsoft Windows and Motif. It also provided a cross-platform UI called Metal that was specific to the Java platform, but looked the same no matter which desktop a user was on.

Changing look-and-feel designs

Before we examine the latest look-and-feel designs, let's demonstrate how to change the look and feel of a Java program, as shown in Listing 1:


Listing 1. Looking up all display modes
  import java.awt.*;
  import javax.swing.*;

  public class Start extends JFrame {
    public Start() {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      Container c = getContentPane();
      JButton button = new JButton("Hello");
      c.add(button, BorderLayout.CENTER);
      setSize(100, 50);
      show();
    }
    public static void main(String[] args) {
      try {
      UIManager.setLookAndFeel(
        UIManager.getCrossPlatformLookAndFeelClassName());
        //UIManager.getSystemLookAndFeelClassName());
      } catch (Exception e) { 
      }
      new Start();
    }
  }

The setLookAndFeel() call of UIManager allows you to pass in the fully qualified class name of the new look-and-feel design. Instead of worrying about what the class name is for the cross-platform Metal UI (javax.swing.plaf.metal.MetalLookAndFeel), you can just ask the system for the name with the getCrossPlatformLookAndFeelClassName() method. On the other hand, getSystemLookAndFeelClassName() will return the UI class name specific for the user's desktop. If the user is running the program on a Windows box, he'll get the Windows UI through the com.sun.java.swing.plaf.windows.WindowsLookAndFeel class. On UNIX boxes, the Motif/CDE interface or the com.sun.java.swing.plaf.motif.MotifLookAndFeel class is returned. The new GTK+ look and feel is available with J2SE 1.4.2, but is not returned as the system look-and-feel class for UNIX machines. This situation will supposedly change with the J2SE 1.5 release. Figure 1 shows what the Start program output looks like when run on a Windows 2000 box:


Figure 1. Cross Platform UI
Cross Platform UI

Windows XP and UNIX users will see a slightly different look for the system, as shown in Figure 2:


Figure 2. Windows Classic UI
Windows Classic UI

Note: Macintosh users of Apple's Java version will have an Aqua look and feel available.

As I indicated, Windows 2000 users will see one UI, and Windows XP users will see a different one. The new Windows XP experience is not a full-fledged set of look-and-feel classes. Instead, the existing set of Windows UI classes will display the classic version of Microsoft Windows for non-XP users and the Windows XP version for Windows XP users. Setting the system property swing.noxp, as shown below, provides a way for Windows XP users to get the more classic Windows interface. There is no option for a non-XP Windows user to get the newer XP interface.

java -Dswing.noxp=true Start


The GTK+ UI

While the new Windows XP experience is just a modified Windows look and feel, the GTK+ UI is brand new and based on GTK+ 2.0 (see Resources for a link to information about GTK+ 2.0). Non-Linux users will probably find this name new to them. Think of it as a typical Linux desktop UI experience (though certainly not the only one available). Many parts of GTK+ are customizable by the user, and by placing configuration files in special locations, the look and feel of the desktop changes accordingly. In addition, capabilities like the multi-document interface (MDI) -- called JInternalFrame in Swing -- are not part of the framework but are left to the underlying window manager. Thus, desktops can be customized by the theme engine. With the Swing UI for GTK+, theming is supported by a project named Metacity (see Resources). By setting the system property, swing.metacitythemename, you can control which GTK+ theme is used. The Crux and Bluecurve themes, in addition to the default theme, are supported. You can then place additional themes in directories specified by the swing.gtkthemedir system property. GTK+ resource files also provide a means to customize the look and feel. Currently, there is no support for creating additional GTK engines. However, you can visit Themes.org to see what may be in store.


SwingSet2 and the new UIs

The easiest way to demonstrate the new look-and-feel designs is by illustrating them with the SwingSet2 demonstration program that comes standard with J2SE, which you'll find in the demo\jfc\SwingSet2 directory wherever you installed J2SE 1.4. Just start up the program with the command java -jar SwingSet2.jar, which uses the -jar option to run the main class specified in the manifest file for the JAR.

The initial screen displays some JInternalFrame components along with several buttons -- items you might find on a typical desktop application. Figure 3 shows what the SwingSet app looks like on a Windows XP machine:


Figure 3. SwingSet with Windows XP look and feel
SwingSet with Windows XP look and feel

Figure 4 shows the GTK+ look and feel:


Figure 4. SwingSet with GTK+ look and feel
SwingSet with GTK+ look and feel

One of the more noticeable Windows changes is to the file dialog. Figure 5 shows what the Windows XP file dialog looks like:


Figure 5. Windows XP file dialog
Windows XP File Dialog

On the GTK+ side, Figure 6 shows a more user-friendly look to its popups:


Figure 6. GTK+ warning dialog
GTK+ Warning Dialog

Summary

J2SE 1.4.2 highlights Sun's commitment to keeping up with the latest standards on the Java desktop. With the Windows XP and GTK+ look-and-feel designs, users will see Java applications that look more like native applications. Besides the new look-and-feel designs, J2SE 1.4.2 includes lots of bug fixes and a JFileChooser that, under certain circumstances, is actually 300 percent faster. (You've got to wonder what took so long if it was that slow, but at least it's faster now.)


Resources

About the author

Author photo

John Zukowski conducts strategic Java consulting with JZ Ventures, Inc. and serves as the resident guru for a number of jGuru's community-driven Java FAQs. His latest books are Java Collections and Definitive Guide to Swing for Java 2 (second edition) from Apress. Contact John at jaz@zukowski.net.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=10816
ArticleTitle=Magic with Merlin: J2SE 1.4.2 gets two new look-and-feel designs
publish-date=05272003
author1-email=jaz@zukowski.net
author1-email-cc=jaloi@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers