Swing技巧. 設定全域字型(sun jdk)

來源:互聯網
上載者:User
Swing技巧. 設定全域字型(sun jdk)

為什麼要這麼做?

   因為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); 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.