java Swing 修改外觀(LookAndFeel)的方法
Java'中的幾種Look and Feel
1、Metal風格 (預設)
String lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
2、Windows風格
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
3、Windows Classic風格
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
4、Motif風格
String lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
5、Mac風格 (需要在相關的作業系統上方可實現)
String lookAndFeel = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
6、GTK風格 (需要在相關的作業系統上方可實現)
String lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
7、可跨平臺的預設風格
String lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
8、當前系統的風格
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
在Java中讓使用者能夠動態地更改應用的外觀,可以給使用者更好地體驗,具體的實現方式是:
1,先使用UIManager.setLookAndFeel(String s)方法設定對應的外觀
2,再使用SwingUtilities.updateComponentTreeUI(Component c)方法立刻更新應用的外觀
這兩個類均在javax.swing包中