How do I set the look and feel for Swing application?

package org.kodejava.example.swing;

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

public class LookAndFeelDemo extends JFrame {
    public LookAndFeelDemo() {

    private void initComponents() {
        setSize(250, 250);
        setTitle("LAF Demo");
        getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));

        JMenu menu = new JMenu("Look and Feel");

        // Get all the available look and feel that we are going to use for
        // creating the JMenuItem and assign the action listener to handle
        // the selection of menu item to change the look and feel.
        UIManager.LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();
        for (UIManager.LookAndFeelInfo lookAndFeelInfo : lookAndFeels) {
            JMenuItem item = new JMenuItem(lookAndFeelInfo.getName());
            item.addActionListener(event -> {
                try {
                    // Set the look and feel for the frame and update the UI
                    // to use a new selected look and feel.
                } catch (Exception e) {

        JMenuBar menuBar = new JMenuBar();

        getContentPane().add(new JButton("Hello"));

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new LookAndFeelDemo().setVisible(true));
Look and Feel Demo

Look and Feel Demo

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you šŸ„³

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.