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