Thursday, April 28, 2016

How to set the Windows look and feel for a Swing application

In this post I am going to show you how to change the default look and feel of a Swing application to a Windows look.

Before











After











Below is the sample code


   /*  
   * This method sets the current System's look and feel for the GUI  
   *  
   * */  
   public void setLookAndFeel(){  
     try {  
       // Set System Look and Feel  
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  
     }  
     catch (UnsupportedLookAndFeelException e) {  
       errorString = e.getMessage();  
       e.printStackTrace();  
     }  
     catch (ClassNotFoundException e) {  
       errorString = e.getMessage();  
       e.printStackTrace();  
     }  
     catch (InstantiationException e) {  
       errorString = e.getMessage();  
       e.printStackTrace();  
     }  
     catch (IllegalAccessException e) {  
       errorString = e.getMessage();  
       e.printStackTrace();  
     }  
   }  


Hope it was useful to you.