首先感謝Could的回複和提醒
關鍵字:Swing JGoodies Look&Feel 中文 漢字
在前一篇文章中提到通過使用第三方的L&F來使Java程式的介面更美觀,但是JGoodies L&F的中文顯示有問題,漢字都變成了方框。 而且Swing Metal 預設的漢字顯示為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));
}
這樣就完成了,來看看效果: