`

swing一次性改变所有字体

阅读更多

swing默认的字体用于显示中文还是觉得有些丑的,以前一次性设置过swing中某个组件的字体,记得代码如下

Font sysFont = new Font("宋体", Font.PLAIN, 12);
UIManager.put("TextField.font", sysFont);
UIManager.put("Label.font", sysFont);

 不过如果swing的带的组件挺多的

TextPane.font
ToggleButton.font
CheckBoxMenuItem.acceleratorFont
Panel.font
PopupMenu.font
OptionPane.font
InternalFrame.titleFont
Label.font
Tree.font
ScrollPane.font
MenuItem.acceleratorFont
TextField.font
Viewport.font
MenuBar.font
FormattedTextField.font
DesktopIcon.font
TableHeader.font
ToolTip.font
PasswordField.font
Table.font
TabbedPane.font
ProgressBar.font
CheckBoxMenuItem.font
ColorChooser.font
Button.font
TextArea.font
Spinner.font
RadioButtonMenuItem.acceleratorFont
RadioButton.font
TitledBorder.font
EditorPane.font
RadioButtonMenuItem.font
ToolBar.font
MenuItem.font
CheckBox.font
Menu.font
Menu.acceleratorFont
ComboBox.font
List.font

 不至于每个都设置吧

public static void initGobalFont(Font font) {
	FontUIResource fontResource 
		= new FontUIResource(font);
	for(Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
		Object key = keys.nextElement();
		Object value = UIManager.get(key);
		if(value instanceof FontUIResource) {
			System.out.println(key);
			UIManager.put(key, fontResource);
		}
	}
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics