How do I get the system look and feel?

Category: javax.swing, viewed: 934 time(s).

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 org.kodejava.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);
    }
}
 
 
Bookmark this example!  

Most Viewed Examples

Google

100 Top & Latest


eXTReMe Tracker
visitor stats