This code snippet shows how to set the look and feel of components to the system.

Listing 1

  1. 1import  javax.swing.UIManager;
  2. 2import  javax.swing.JFrame;
  3. 3import  javax.swing.JPanel;
  4. 4import  javax.swing.JButton;
  5. 5
  6. 6class  Main{
  7. 7        
  8. 8        public  static  void  main(String  args[]){
  9. 9                try{
  10. 10                        //  Set  System  L&F
  11. 11                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  12. 12                }  
  13. 13                catch  (Exception  e)  {
  14. 14                        //  handle  exception
  15. 15                }
  16. 16                Main  main  =  new  Main();
  17. 17        }
  18. 18        
  19. 19        public  Main(){
  20. 20                JFrame  frame  =  new  JFrame();
  21. 21                JPanel  panel  =  new  JPanel();
  22. 22
  23. 23                JButton  button1  =  new  JButton("Button 1");
  24. 24                JButton  button2  =  new  JButton("Button 2");
  25. 25                
  26. 26                panel.add(button1);
  27. 27                panel.add(button2);
  28. 28                
  29. 29                frame.add(panel);
  30. 30                
  31. 31                frame.setSize(300,300);
  32. 32                frame.setVisible(true);
  33. 33        }
  34. 34}