Wednesday, March 09, 2005

Installed Look and Feels

"WYSIWIG: What you see is fake hair."
Anonymous

The appearance and behavior of a GUI is called "look and feel". Playing around with Swing (Java SDK 1.4.2-beta "Mantis"), you would perhaps wonder what look and feels are installed.

Because Java is platform independent, you should always find the installed look and feels before letting the user select look and feel.

Create a JButton with NetBeans IDE, called getInstalledLookAndFeels, and add the following code.

    private void getInstalledLookAndFeelsActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        UIManager.LookAndFeelInfo[] lookAndFeelInfo = UIManager.getInstalledLookAndFeels();
        for (int i = 0; i < lookAndFeelInfo.length; i++) {
                System.out.println(lookAndFeelInfo[i].getName() + ", " + 
                    lookAndFeelInfo[i].getClassName());
        }
    }

Under Linux, Swing reports the following installed look and feels:

Metal, javax.swing.plaf.metal.MetalLookAndFeel
CDE/Motif, com.sun.java.swing.plaf.motif.MotifLookAndFeel
Windows, com.sun.java.swing.plaf.windows.WindowsLookAndFeel

Seems like Java SDK 1.4.2-beta missed the new look and feel called GTK+ with the class name "com.sun.java.swing.plaf.gtk.GTKLookAndFeel". Also, Java SDK 1.4.2-beta reports the bogus look and feel for Microsoft Windows with the class name "com.sun.java.swing.plaf.windows.WindowsLookAndFeel". By the way, this is Bug Id 4843282 in Suns bug database.

No comments: