Picses' sky

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

          Swing技巧. 設置全局字體[zz]

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

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

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

          Feedback

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

          建設不要這樣直接貼代碼, 交流思想才是重要的。  回復  更多評論   

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

          ok, i see  回復  更多評論   

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

          次方法的調用必須放在UIManager.setLookAndFeel(w);之后,因為具體的laf實現可能添加新的鍵值對。并且方法修改如下:

          //設置全局字體
          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));

          }
          }

          主站蜘蛛池模板: 蚌埠市| 遂宁市| 滨海县| 毕节市| 迁西县| 西吉县| 黄龙县| 治县。| 龙胜| 乐安县| 青海省| 东台市| 铜梁县| 贵溪市| 林州市| 汉寿县| 象州县| 阿合奇县| 溧水县| 九江县| 龙游县| 偃师市| 烟台市| 嵊泗县| 彭泽县| 锡林浩特市| 温州市| 五峰| 子洲县| 耒阳市| 调兵山市| 镇沅| 德格县| 新余市| 广西| 松阳县| 华容县| 温宿县| 方正县| 松溪县| 连州市|