kooyee ‘s blog

          開源軟件, 眾人努力的結晶, 全人類的共同財富
          posts - 103, comments - 55, trackbacks - 0, articles - 66
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          『SWT』選項卡的激活與非激活狀態

          Posted on 2008-06-11 22:58 kooyee 閱讀(1675) 評論(0)  編輯  收藏 所屬分類: GUI骨衣
          當存在多個容器或選項卡容器時,其中一個選項卡在激活(選擇時)與非激活時標簽的顏色變化。 例如eclipse中點擊周圍的小窗口上的選項卡后,主窗口的選項卡標簽由藍色變為白色,反之亦然。

          我琢磨出來實現這個效果的方法是,首先給選項卡中的控件加入focusLost事件(如果表現背景使用了漸變色,在這里改變成新的背景色的話,也要使用同樣的Method和值為null的Color array來清空原來的背景色或定義新的顏色)
          text.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {   
                      
                      
          public void focusLost(org.eclipse.swt.events.FocusEvent e) {
                          Color[] c 
          = {nullnull,null};
                          
          int[] i = {10,100};
                          tab.setSelectionBackground(c,i);
                      tab.setSelectionForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
                      }

          其次當再次選擇非激活的選項卡時,再改變會激活狀態的顏色。給選項卡中的控件加入focusGained事件并且選項卡加入selection和mouseDown事件。
          selection和mouseDown事件分別是當選項卡被點擊和選擇時focus選項卡中的控件, focusGained事件改變標簽顏色
          tab2.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                      
          public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                          text.forceFocus();
                      }

                  }
          );
                  tab2.addMouseListener(
          new org.eclipse.swt.events.MouseAdapter() {
                      
          public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
                          text.forceFocus();
                      }

                  }
          );

          private void disactive (CTabFolder arg0){
                  Color[] c 
          = {nullnull,null};
                  
          int[] i = {10,100};
                  arg0.setSelectionBackground(c,i);
                  arg0.setSelectionForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
              }

              
              
          private void active (CTabFolder arg0){
                  Color[] color
          =new Color[4];
                  color[
          0]=new Color(Display.getCurrent(), 078255);
                  color[
          1]=new Color(Display.getCurrent(), 098255);  
                  color[
          2]=Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);    
                  color[
          3]=Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);      
                  
          int[] intArray=new int[]{50,70,100};
                  arg0.setSelectionBackground(color, intArray, 
          true);
                  arg0.setSelectionForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
              }

          控件的focusGained事件
          text.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {   
                      
          public void focusGained(org.eclipse.swt.events.FocusEvent e) {
                          active(tab2);
                      }

                  }
          );
          主站蜘蛛池模板: 溧阳市| 安阳县| 竹北市| 加查县| 克什克腾旗| 吉木乃县| 阜阳市| 河北省| 靖宇县| 修水县| 阜南县| 马关县| 高青县| 合肥市| 宜兰市| 防城港市| 邢台市| 平南县| 巴林右旗| 丰城市| 佛教| 巴塘县| 宝山区| 阜新| 安国市| 长宁区| 开鲁县| 云霄县| 常州市| 龙泉市| 崇明县| 拜泉县| 枞阳县| 南康市| 长岛县| 芜湖市| 清原| 忻城县| 周宁县| 苏州市| 武功县|