技术分享 SWING 查看内容

SWING设置全局字体(SUN JDK)

老高 | 发布于 2018-06-20 21:55| 浏览()| 评论() | 收藏() | 点赞() | 打印

摘要: 为什么要这么做? 因为java默认的字体显示中文都很难看 因为比如jgoodies这样的skin默认不支持中文 因为jdk1.4中文字体mapping有严重bug,用过IDEA的人都知道 ​因为大家只有sun的jdk可用,ibm的,bea的都不适合跑client

为什么要这么做?

因为java默认的字体显示中文都很难看

因为比如jgoodies这样的skin默认不支持中文

因为jdk1.4中文字体mapping有严重bug,用过IDEA的人都知道

因为大家只有sun的jdk可用,ibm的,bea的都不适合跑client

if you are smart....

//设置全局字体
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);
    }
}

if you aren't...

Font font = new Font("Dialog",Font.PLAIN,12);
UIManager.put("ToolTip.font",font);
UIManager.put("Table.font",font);
UIManager.put("TableHeader.font",font); 
UIManager.put("TextField.font",font); 
UIManager.put("ComboBox.font",font); 
UIManager.put("TextField.font",font); 
UIManager.put("PasswordField.font",font); 
UIManager.put("TextArea.font",font); 
UIManager.put("TextPane.font",font); 
UIManager.put("EditorPane.font",font); 
UIManager.put("FormattedTextField.font",font); 
UIManager.put("Button.font",font); 
UIManager.put("CheckBox.font",font); 
UIManager.put("RadioButton.font",font); 
UIManager.put("ToggleButton.font",font); 
UIManager.put("ProgressBar.font",font); 
UIManager.put("DesktopIcon.font",font); 
UIManager.put("TitledBorder.font",font); 
UIManager.put("Label.font",font); 
UIManager.put("List.font",font); 
UIManager.put("TabbedPane.font",font); 
UIManager.put("MenuBar.font",font); 
UIManager.put("Menu.font",font); 
UIManager.put("MenuItem.font",font); 
UIManager.put("PopupMenu.font",font); 
UIManager.put("CheckBoxMenuItem.font",font); 
UIManager.put("RadioButtonMenuItem.font",font); 
UIManager.put("Spinner.font",font); 
UIManager.put("Tree.font",font); 
UIManager.put("ToolBar.font",font); 
UIManager.put("OptionPane.messageFont",font); 
UIManager.put("OptionPane.buttonFont",font);


发表评论(对文章涉及的知识点还有疑问,可以在这里留言,老高看到后会及时回复的。)

表情