Swing技巧. 设置全局字体

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

你可能感兴趣的:(swing)