JAVA Swing设置界面统一字体
//统一界面字体
private static void InitGlobalFont(Font font) {
FontUIResource fontRes = new FontUIResource(font);
for (Enumeration<Object> keys = UIManager.getDefaults().keys();
keys.hasMoreElements(); ) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
UIManager.put(key, fontRes);
}
}
调用: InitGlobalFont(new Font("宋体", Font.PLAIN, 12));
UIManager.put("Menu.font", new Font("宋体", Font.PLAIN, 12));//设置Menubar的字体
UIManager.put("MenuItem.font", new Font("宋体", Font.PLAIN, 12));//设置MenuItem的字体
//设置界面外观风格
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());//操作系统的界面风格
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");//Java 6 Update 10后的新的Swing 跨平台界面外观