Open In App
Related Articles

Java Swing | Look and Feel

Improve Article
Save Article
Like Article

Swing is GUI Widget Toolkit for Java. It is an API for providing Graphical User Interface to Java Programs. Unlike AWT, Swing components are written in Java and therefore are platform-independent. Swing provides platform specific Look and Feel and also an option for pluggable Look and Feel, allowing application to have Look and Feel independent of underlying platform.
Initially there were very few options for colors and other settings in Java Swing, that made the entire application look boring and monotonous. With the growth in Java framework, new changes were introduced to make the UI better and thus giving developer opportunity to enhance the look of a Java Swing Application.

“Look” refers to the appearance of GUI widgets and “feel” refers to the way the widgets behave.
Sun’s JRE provides the following L&Fs:

  1. CrossPlatformLookAndFeel: this is the “Java L&F” also known as “Metal” that looks the same on all platforms. It is part of the Java API (javax.swing.plaf.metal) and is the default.
  2. SystemLookAndFeel: here, the application uses the L&F that is default to the system it is running on. The System L&F is determined at runtime, where the application asks the system to return the name of the appropriate L&F.
    For Linux and Solaris, the System L&Fs are “GTK+” if GTK+ 2.2 or later is installed, “Motif” otherwise. For Windows, the System L&F is “Windows”.
  3. Synth: the basis for creating your own look and feel with an XML file.
  4. Multiplexing: a way to have the UI methods delegate to a number of different look and feel implementations at the same time.

We can use UIManager to load the L&F class directly from classpath. For which the code goes like this:

UIManager.setLookAndFeel("fully qualified name of look and feel");

For example, following code changes application Look and Feel to Motif Look And Feel:

UIManager.setLookAndFeel ("");

// Java sample code to get the list of
// installed Look and Feel themes, here is a sample code:
import javax.swing.UIManager;
public class MainClass {    public static void main(String[] a)
        UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
        for (UIManager.LookAndFeelInfo look : looks) {


We will see different Look and Feel themes with the help of a simple calculator program:

  1. CrossPlatformLookAndFeel:

    // Java program to illustrate
    // CrossPlatformLookAndFeel
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.UIManager;
    import javax.swing.JFrame;
    class Awt implements ActionListener {
        JFrame f;
        JButton addbut, subbut, mulbut, divbut, b5;
        JTextField t1, t2, t3;
        JLabel l, l1;
            f = new JFrame("Cross Platform Look and Feel");
            t1 = new JTextField("             ");
            t2 = new JTextField("             ");
            t3 = new JTextField("             ");
            addbut = new JButton("Add");
            subbut = new JButton("Sub");
            mulbut = new JButton("Mul");
            divbut = new JButton("Div");
            l = new JLabel();
            l1 = new JLabel();
        public void awt1()
            f.setLayout(new GridLayout(3, 2));
        public void actionPerformed(ActionEvent e)
            String s = new String(e.getActionCommand());
            if ((s).equals("Add")) {
                int a = Integer.parseInt(t1.getText());
                int b = Integer.parseInt(t2.getText());
                Integer c = a + b;
            else if ((s).equals("Sub")) {
                int a = Integer.parseInt(t1.getText());
                int b = Integer.parseInt(t2.getText());
                Integer c = a - b;
            else if ((s).equals("Mul")) {
                int a = Integer.parseInt(t1.getText());
                int b = Integer.parseInt(t2.getText());
                Integer c = a * b;
        public static void main(String args[])
            try {
            catch (Exception e) {
                System.out.println("Look and Feel not set");
            Awt a = new Awt();


    You can also use actual class name of Look And Feel as argument to UIManager.setLookAndFeel(). For example,
    // Set cross-platform Java L&F (also called “Metal”)

  2. MotifLookAndFeel: Just change Line number 14 and 79 to:
     Line 14: f=new JFrame("Motif Look and Feel");
    Line 79: UIManager.setLookAndFeel("");


  3. SystemLookAndFeel: Change Line number 14 and 79 to:
    Line 14: f=new JFrame("System Look and Feel");
    Line 79: UIManager.setLookAndFeel("");


  4. WindowsClassicLookAndFeel: Change Line number 14 and 79 to:
    Line 14: f=new JFrame("WindowsClassic Look and Feel");
    Line 79: UIManager.setLookAndFeel("");


  5. NimbusLookAndFeel: Change Line number 14 and 79 to:
    Line 14: f=new JFrame("Nimbus Look and Feel");
    Line 79: UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");


Specifying Look And Feel using Command Line Arguments

You can specify the Look And Feel by using -D flag at the command line to set the swing.defaultlaf property. Example –
We will run the above code excluding Line 76 and executing following command:

java Awt


Specifying Look And Feel by editing file

In this we will edit file to set the swing.defaultlaf property. This file is located in lib directory. Here is an example-


Themes were introduced to change colors and fonts of default Java Metal Look And Feel. A constant can be initialised to one of 3 values:

  • Default Metal
  • Ocean
  • Test

There is option for professional themes which one can download and use in the code. Here is the list of professional themes that are available:

  1. Substance
  2. Sea Glass
  3. Info Look And Feel
  4. Pgs Look And Feel
  5. Quaqua Look And Feel
  6. Oyaha
  7. Liquid Look And Feel
  8. JTattoo



Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
  • Comprehensive Course
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world Projects
  • Proven Track Record with 100,000+ Successful Geeks

Last Updated : 02 May, 2018
Like Article
Save Article
Similar Reads
Complete Tutorials