现在的位置: 首页 > 综合 > 正文

JFileChooser 中文显示

2018年05月23日 ⁄ 综合 ⁄ 共 412字 ⁄ 字号 评论关闭

问题:使用JFileChooser 时中文显示为方框,直接对JFileChooser 使用setFont无效。

解决方法:

因为JFileChooser本身就是许多component的集合,只要用一个递归函数即可设定其中的字体。代码如下:
private static void updateFont(Component comp, Font font) {
	comp.setFont(font);
	if (comp instanceof Container) {
		Container c = (Container) comp;
		int n = c.getComponentCount();
		for (int i = 0; i < n; i++) {
			updateFont(c.getComponent(i), font);
		}
	}
}

调用方法:
JFileChooser jfChooser = new JFileChooser(); 
updateFont(jfChooser,new Font("宋体",0,15));



抱歉!评论已关闭.