JFrame and Nimbus Look And Feel

MOD picture MOD · Sep 30, 2011 · Viewed 15k times · Source

I use Nimbus Look and Feel in a project. However, although every GUI JComponent have a Look and Feel of Nimbus, JFrame always have Windows Look and Feel.

How can JFrame have Nimbus Look And Feel?

Edit: Operating System : Windows XP

Answer

Marek Sebera picture Marek Sebera · Sep 30, 2011

Try using this:

JFrame.setDefaultLookAndFeelDecorated(true); //before creating JFrames

For more info., see How to Set the Look and Feel in the tutorial.


import javax.swing.*;

class FrameLook {

    public static void showFrame(String plaf) {
        try {
            UIManager.setLookAndFeel(plaf);
        } catch(Exception e) {
            e.printStackTrace();
        }
        JFrame f = new JFrame(plaf);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        f.setSize(400,100);
        f.setLocationByPlatform(true);
        f.setDefaultLookAndFeelDecorated(true);
        f.setVisible(true);
    }

    public static void main(String[] args) {
        showFrame(UIManager.getSystemLookAndFeelClassName());
        showFrame(UIManager.getCrossPlatformLookAndFeelClassName());
        showFrame("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    }
}

Frame title bar Look'n'Feel