Java - Look And Feel

To make our application look prettier, the Swing architecture is made to change the look and feel of your application or GUI by separating each component into two different classes: JComponent and ComponentUI. For example, each instance of JList has a concrete ListUI implementation that inherits from the ComponentUI.

superclass, use the method:  UIManager.setLookAndFeel(LookAndFeel l ) with the class name of LookAndFeel as the argument.

After the change, you need to update the component tree by calling the method  SwingUtilities.updateComponentTreeUI(frame);

Example

In this example, we are declaring a LOOKANDFEEL constant that will contain one of the following valid values: Metal, System, Pattern, and GTK. This code works under Eclipse and Netbeans.

import javax.swing.*; 
import java.awt.*;

public class LookAndFeelTest extends JFrame{

public LookAndFeelTest(){
//initialize lookandfeel
initLookAndFeel();
//be sure that the learning has been applied
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and configure the window
JFrame frame = new JFrame("SwingApp");
Component contents = createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

SwingUtilities.updateComponentTreeUI(frame);
//display window
frame.pack();
frame.setVisible(true);
}

/*
* Specify the lookandfeel appearance to use by setting
* the LOOKANDFEEL constant
*/
final static String LOOKANDFEEL = "Metal";

public Component createComponents() {
JButton button = new JButton("Button");
JLabel label = new JLabel(LOOKANDFEEL);

JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(button);
panel.add(label);
panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));

return panel;
}

private static void initLookAndFeel() {
String lookAndFeel = null;

if(LOOKANDFEEL != null) {
switch(LOOKANDFEEL){
"Metal" box:lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
estate;
"System":lookAndFeel = UIManager.getSystemLookAndFeelClassName();
estate;
"Pattern":lookAndFeel = "com.sun.java.swing.plaf.pattern.PatternLookAndFeel";
estate;
box "GTK":lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
estate;
}

try {
UIManager.setLookAndFeel(lookAndFeel);
}
catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) {
new LookAndFeelTest();
}
}
Output:
look and feel Metal GTK LookAndFeel

System

If you want to keep the original theme of your operating system as in this example that recovers the appearance of Windows 7.

lookAndFeel = UIManager.getSystemLookAndFeelClassName(); 
Out:
look and feel SystemLookAndFeel

Motif

lookAndFeel="com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 
Out:
look and feel MotifLookAndFeel

References:
Oracle Documentation: How to set Look and Feel.
Developpez.net: Java GUI:Look & Feel