Picses' sky

          Picses' sky
          posts - 43, comments - 29, trackbacks - 0, articles - 24

          Swing技巧. 設(shè)置全局字體[zz]

          Posted on 2007-07-23 08:16 Matthew Chen 閱讀(1029) 評(píng)論(0)  編輯  收藏 所屬分類: Java SE

          Swing技巧. 設(shè)置全局字體

          Swing技巧. 設(shè)置全局字體(sun jdk)

          為什么要這么做?

             因?yàn)閖ava默認(rèn)的字體顯示中文都很難看

             因?yàn)楸热鏹goodies這樣的skin默認(rèn)不支持中文

             因?yàn)閖dk1.4中文字體mapping有嚴(yán)重bug,用過(guò)IDEA的人都知道

             因?yàn)榇蠹抑挥衧un的jdk可用,ibm的,bea的都不適合跑client

          if you are smart....
          //設(shè)置全局字體
          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); 

          posted on 2005-07-20 17:33 tech.cap 閱讀(2194) 評(píng)論(3)  編輯 收藏 引用 所屬分類: javatips

          Feedback

          # re: Swing技巧. 設(shè)置全局字體 2005-07-20 20:12 dudu

          建設(shè)不要這樣直接貼代碼, 交流思想才是重要的。  回復(fù)  更多評(píng)論   

          # re: Swing技巧. 設(shè)置全局字體 2005-07-21 01:01 cap

          ok, i see  回復(fù)  更多評(píng)論   

          # re: Swing技巧. 設(shè)置全局字體 2005-12-24 18:24 cofbean

          次方法的調(diào)用必須放在UIManager.setLookAndFeel(w);之后,因?yàn)榫唧w的laf實(shí)現(xiàn)可能添加新的鍵值對(duì)。并且方法修改如下:

          //設(shè)置全局字體
          public static void initGlobalFontSetting(String font){

          for(Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();){

          Object key = keys.nextElement();
          Object value = UIManager.get(key);

          if(value instanceof FontUIResource){
          FontUIResource rs=(FontUIResource)value;
          Font fontRes = new Font(font,rs.getStyle(),rs.getSize());
          UIManager.put(key, new FontUIResource(fontRes));

          }
          }

          主站蜘蛛池模板: 马山县| 罗山县| 桂平市| 托里县| 宁都县| 阳原县| 德令哈市| 麻城市| 阿拉善右旗| 丰城市| 平泉县| 浮山县| 平乡县| 栖霞市| 鄄城县| 湛江市| 资兴市| 辰溪县| 长岛县| 石景山区| 尚义县| 黔西县| 洛扎县| 柞水县| 延安市| 濉溪县| 九江县| 含山县| 吴桥县| 满洲里市| 饶平县| 夏河县| 苗栗县| 三门县| 黄平县| 桦川县| 麟游县| 克什克腾旗| 抚顺县| 武乡县| 积石山|