Search This Blog

How to Change Look and Feel of a Java Application

The following code fragment which can be used within main method or in constructor of the class tells you how to change the look and feel of a java program (java application). This sample code sets the LookAndFeel of the java application into Windows Look and Feel.




try {     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())         {         if ("Windows".equals(info.getName()))             {             javax.swing.UIManager.setLookAndFeel(info.getClassName());             break;             }         }     }catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {         Logger.getLogger(WizardForm.class.getName()).log(Level.SEVERE, null, ex);     }

You can change the part shown in bold (Windows) to Nimbus, Metal, Motif, System, GTK etc. YOu can change the Look and Feel (LookAndFeel) of your java application simply by changing the text shown bold into above specified names of Look and Feels. To set to Nimbus Look And Feel, replace 'Windows' in the code with 'Nimbus'. Similarly you can apply Metal, Motif, System or GTK as your application's Look and Feel. You can also install third party look and feels by adding their library jar file into your app.

No comments:

Post a Comment