Java Swing UIManager set look and fell to system look and feel

Description

Java Swing UIManager set look and fell to system look and feel

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Main extends JFrame {

  public static void main(String[] args) {
    String lyrics = "OK";

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout(10, 10));

    JButton label = new JButton(lyrics);

    panel.add(label, BorderLayout.CENTER);

    JFrame f = new JFrame();
    f.add(panel);/*from   w  w w . j  av a  2s.co  m*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

    try {

      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    } catch (UnsupportedLookAndFeelException e) {
      // handle exception
    } catch (ClassNotFoundException e) {
      // handle exception
    } catch (InstantiationException e) {
      // handle exception
    } catch (IllegalAccessException e) {
      // handle exception
    }
  }
}



PreviousNext

Related