常用鏈接

          統計

          最新評論

          改變Swing的LookAndFeel (轉)

          要改變Swing默認的LookAndFeel,網上都說用UIManager下的一個靜態方法setLookAndFeel即可,但是我用了這個方法有半年的時間也沒有看到真正的WindowsLookAndFeel。昨天網上無意中才看到正解,要設置LookAndFeel,不僅要調用上面提到的方法,還要調用一個SwingUtilities類中的靜態方法updateComponentTreeUI。即

          try{
              javax.swing.UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
              javax.swing.SwingUtilities.updateComponentTreeUI(this);
          }catch(javax.swing.UnsupportedLookAndFeelException e){
              e.printStackTrace();
          }


          后者在運行時對整個ComponentTree進行更新,應用當前的UI設置。


          public static void setLookAndFeel(String className, java.awt.Component c) {
              try {
                UIManager.setLookAndFeel(className);
                SwingUtilities.updateComponentTreeUI(c);//注意這行
              }
              catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null,
                                              "不好意思,setLookAndFeel時出錯了:( Errormsg:" + ex,
                                              "setLookAndFeel",
                                              JOptionPane.INFORMATION_MESSAGE);
              }

          posted on 2007-11-15 16:42 九寶 閱讀(1047) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 玉环县| 宣城市| 苍溪县| 榕江县| 巴林左旗| 芮城县| 邛崃市| 乃东县| 定边县| 巴青县| 黑水县| 宣威市| 东乡| 普格县| 巫山县| 宁德市| 涿州市| 乐东| 宁乡县| 兴安盟| 叶城县| 砚山县| 仙居县| 石阡县| 定兴县| 怀集县| 娄烦县| 诏安县| 柳州市| 玛纳斯县| 建宁县| 邛崃市| 鄯善县| 晋州市| 四子王旗| 定襄县| 朔州市| 凉山| 永靖县| 正宁县| 建水县|