<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>
首先感謝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));
}
這樣就完成了,來看看效果:
關鍵字: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));
}
這樣就完成了,來看看效果:


更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
