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,用過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));

          }
          }

          主站蜘蛛池模板: 基隆市| 古田县| 玉溪市| 屏山县| 云阳县| 泰州市| 和田县| 如东县| 准格尔旗| 资阳市| 莱州市| 科尔| 建宁县| 波密县| 武强县| 铜鼓县| 衡南县| 贵州省| 六枝特区| 广河县| 元氏县| 杭锦旗| 原平市| 绥中县| 大兴区| 论坛| 体育| 手游| 恩施市| 山东省| 陆良县| 盐山县| 察隅县| 昔阳县| 昌黎县| 淮南市| 杂多县| 丹阳市| 柳河县| 兰溪市| 芦山县|