how-to

Others

How to set look and feel in running application

For this section you need to use:

import javax.swing.*;

When look and feel is initialized, you can change it too. Use this code:

try {

  UIManager.setLookAndFeel( "javax.swing.plaf.nimbus.NimbusLookAndFeel" );
      
  SwingUtilities.updateComponentTreeUI( this );      
  this.pack(); 
      
} catch ( ClassNotFoundException ex ) {
} catch ( InstantiationException ex ) {
} catch ( IllegalAccessException ex ) {
} catch ( UnsupportedLookAndFeelException ex ) {
}

The above picture shows change from Windows look and feel to Nimbus look and feel.

In JDK 1.7 exists these look and feel predefined classes:

Property Value
com.sun.java.swing.plaf.windows.WindowsLookAndFeelWindows
javax.swing.plaf.nimbus.NimbusLookAndFeelNimbus
javax.swing.plaf.metal.MetalLookAndFeelMetal
com.sun.java.swing.plaf.motif.MotifLookAndFeelMotif