swing全局字体设置
时间:2010-09-12 来源:李念间
由于Swing中默认都是使用了tohoma字体,而不是Dialog 这样的family font。 要使中文显示正常,把字体设置成Dialog即可。 Could的方法要对每个组件设置字体比较麻烦,下面使用全局字体设置来解决这个问题。
public static void initGlobalFontSetting(Font fnt){
FontUIResource fontRes = new FontUIResource(fnt);
for(Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();){
Object key = keys.nextElement();
Object value = UIManager.get(key);
if(value instanceof FontUIResource)
UIManager.put(key, fontRes);
}
}
...........
try {
UIManager.setLookAndFeel(
//UIManager.getCrossPlatformLookAndFeelClassName()
//UIManager.getSystemLookAndFeelClassName()
//new com.sun.java.swing.plaf.motif.MotifLookAndFeel()
//"com.jgoodies.looks.windows.WindowsLookAndFeel"
"com.jgoodies.looks.plastic.PlasticLookAndFeel"
// "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"
//"com.jgoodies.looks.plastic.PlasticXPLookAndFeel"
);
initGlobalFontSetting(new Font("Dialog",Font.PLAIN,12));
}