Java‘中的几种Look and Feel 1、Metal风格 (默认) String lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel"; UIManager.setLookAndFee(lookAndFeel);
2、Windows风格 String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; UIManager.setLookAndFee
(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)方法立刻更新应用
DEMO
package com.star.update.lunach;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Test {
public static void main(String[] args) {
System.out.println(getJBossHomeByCHoose());
}
public static String getJBossHomeByCHoose() {
initUIManager();
JFileChooser fileChooser = new JFileChooser("d:");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fileChooser.showOpenDialog(fileChooser);
if (returnVal == JFileChooser.APPROVE_OPTION) {
return fileChooser.getSelectedFile().getAbsolutePath();
}
return null;
}
private static void initUIManager() {
String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
}