java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get the system look and feel?

The UIManager.getSystemLookAndFeelClassName() return the current system look and feel for swing application. Don't forget to call the SwingUtilities.updateComponentTreeUI(frame) after setting the LAF.

package com.javacoderanch.example.swing;

import javax.swing.*;

public class SystemLAFDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("System LAF Demo");

        try {
            //
            // Use the system look and feel for the swing application
            //
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        SwingUtilities.updateComponentTreeUI(frame);

        frame.setVisible(true);
    }
}