How do I get the available Swing look and feel?

The code snippet below describe how we can obtain the available look and feel in the current Swing platform. This information can then be made available to the user, so they can change to look and feel of the application in their preferences.

package org.kodejava.swing;

import javax.swing.UIManager;

public class AvailableLookAndFeel {
    public static void main(String[] args) {
        UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();

        for (UIManager.LookAndFeelInfo lookAndFeel : lookAndFeels) {
            // Get the name of the look and feel
            String name = lookAndFeel.getName();
            System.out.println("Name      = " + name);

            // Get the implementation class for the look and feel
            String className = lookAndFeel.getClassName();
            System.out.println("ClassName = " + className);
        }
    }
}

Below is the list of available look and feel produces by the code snippet above.

Name      = Metal
ClassName = javax.swing.plaf.metal.MetalLookAndFeel
Name      = Nimbus
ClassName = javax.swing.plaf.nimbus.NimbusLookAndFeel
Name      = CDE/Motif
ClassName = com.sun.java.swing.plaf.motif.MotifLookAndFeel
Name      = Windows
ClassName = com.sun.java.swing.plaf.windows.WindowsLookAndFeel
Name      = Windows Classic
ClassName = com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel
Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.