JFileChooser 中文顯示

問題:使用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));





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章