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. These 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.example.swing;

import javax.swing.*;

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      = Mac OS X
ClassName = com.apple.laf.AquaLookAndFeel

Wayan

Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me by donating.

Leave a Reply