<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.html" frameborder="0" width="468" scrolling="no" height="60"></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));

}

这样就完成了,来看看效果:

让Java Swing显示中文更美观

让Java Swing显示中文更美观




Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=603338


相关文章: