Set Java Look and Feel

You can set the look and feel for your program whether it is an application or applet. The following code is inserted into the class definition (outside of any of the methods). The first commented out line uses the LookAndFeel class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.The second commented out statement sets the LookAndFeel class that implements the default cross platform look and feel, i.e. the "Java Look and Feel", or JLF. The last two set the look and feel to Metal and Motif respectively.

//Set the look and feel for the program
   static{
    try  {
     // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
       UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
     //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        }
    catch  (Exception e) {}
   }

Here is the same window and InternalFrame with the three different look and feel options you might use.


Windows

Metal

Motif

For a complete overview of Look and Feel check Sun's look and feel page and the class summary page .


Summary Class UIManager

java.lang.Object | +--javax.swing.UIManager public class UIManager extends Object implements Serializable This class keeps track of the current look and feel and its defaults. We manage three levels of defaults: user defaults, look and feel defaults, system defaults. A call to UIManager.get() checks all three levels in order and returns the first non-null value for a key, if any. A call to UIManager.put() just affects the user defaults. Note that a call to setLookAndFeel() doesn't affect the user defaults, it just replaces the middle defaults "level". Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence. See Also: Serialized Form

Inner Class Summary

static class UIManager.LookAndFeelInfo           Provide a little information about an installed LookAndFeel for the sake of configuring a menu or for initial application set up.  

Constructor Summary

UIManager()              

Method Summary

static void addAuxiliaryLookAndFeel(LookAndFeel laf)           Add a LookAndFeel to the list of auxiliary look and feels. static void addPropertyChangeListener(PropertyChangeListener listener)           Add a PropertyChangeListener to the listener list. static Object get(Object key)           Returns an object from the defaults table. static LookAndFeel[] getAuxiliaryLookAndFeels()           Return the list of auxiliary look and feels (can be null). static Border getBorder(Object key)           Returns a border from the defaults table. static Color getColor(Object key)           Returns a drawing color from the defaults table. static String getCrossPlatformLookAndFeelClassName()           Returns the name of the LookAndFeel class that implements the default cross platform look and feel, i.e. the "Java Look and Feel", or JLF. static UIDefaults getDefaults()           Returns the default values for this look and feel. static Dimension getDimension(Object key)           Returns a dimension from the defaults table. static Font getFont(Object key)           Returns a drawing font from the defaults table. static Icon getIcon(Object key)           Returns an Icon from the defaults table. static Insets getInsets(Object key)           Returns an Insets object from the defaults table. static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels()           Return an array of objects that provide some information about the LookAndFeel implementations that have been installed with this java development kit. static int getInt(Object key)           Returns an int from the defaults table. static LookAndFeel getLookAndFeel()           Returns The current default look and feel, or null. static UIDefaults getLookAndFeelDefaults()           Returns the default values for this look and feel. static String getString(Object key)           Returns a string from the defaults table. static String getSystemLookAndFeelClassName()           Returns the name of the LookAndFeel class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class. static ComponentUI getUI(JComponent target)           Returns the L&F&F object that renders the target component. static void installLookAndFeel(String name, String className)           Creates a new look and feel and adds it to the current array. static void installLookAndFeel(UIManager.LookAndFeelInfo info)           Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]). static Object put(Object key, Object value)           Stores an object in the defaults table. static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)           Remove a LookAndFeel from the list of auxiliary look and feels. static void removePropertyChangeListener(PropertyChangeListener listener)           Remove a PropertyChangeListener from the listener list. static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)           Replaces the current array of installed LookAndFeelInfos. static void setLookAndFeel(LookAndFeel newLookAndFeel)           Set the current default look and feel using a LookAndFeel object. static void setLookAndFeel(String className)           Set the current default look and feel using a class name.   Methods inherited from class java.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait