Java Swing UIManager set look and feel from look and feel list

Description

Java Swing UIManager set look and feel from look and feel list

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
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   www.j  a v  a  2  s .  co  m*/
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);

    try {
      String lnf = null;
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equalsIgnoreCase(info.getName())) {
            lnf = info.getClassName();
            UIManager.setLookAndFeel(lnf);
            break;
        }
      }
    } catch (UnsupportedLookAndFeelException e) {
      // handle exception
    } catch (ClassNotFoundException e) {
      // handle exception
    } catch (InstantiationException e) {
      // handle exception
    } catch (IllegalAccessException e) {
      // handle exception
    }
  }
}



PreviousNext

Related