JFrame and Nimbus Look And Feel

后端 未结 5 1884
名媛妹妹
名媛妹妹 2021-01-03 09:54

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 JFr

5条回答
  •  清酒与你
    2021-01-03 10:30

    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

提交回复
热议问题