| 1.實現(xiàn)窗口的透明功能 通過函數(shù)Shell.setAlpha(int alpha)設(shè)置窗口的透明度,alpha取值0到255,0為全透明。透明窗口的實現(xiàn)需要所在系統(tǒng)的支持,在不支持的系統(tǒng)下setAlpha會被忽略。 
 2.實現(xiàn)全屏模式 
 在Ecipse 3.4M3以后的版本中要設(shè)置全屏可以調(diào)用 Shell.setFullScreen(true)即可; 在之前版本的RCP平臺中實現(xiàn)全屏,需要顯式設(shè)置Shell的樣式為SWT.NO_TRIM (表示Shell無邊框和標(biāo)題欄)和SWT.ON_TOP (表示Shell始終在最前端顯示),然后把Shell的大小設(shè)置為覆蓋全屏幕即可達到目的; 順便介紹一下樣式 SWT.TOOL ,在API中是這樣解釋的: A tool window is a window intended to be used as a floating toolbar. It typically has a title bar that is shorter than a normal title bar,and the window title is typically drawn using a smaller font. 意思是,標(biāo)識為TOOL樣式的窗口建議作為一個浮動工具條使用,它的邊框和標(biāo)題欄比普通的Shell要小,而且邊框上的字體也小。 
 
 3.使SWT的Table根據(jù)TableItem顯示Tooltip 默認(rèn)情況下,SWT的Table只會給整個Table設(shè)置Tooltip,要對每一個TableItem設(shè)置Tooltip的話,就要監(jiān)聽鼠標(biāo)事件了,代碼如下: 
 
 table.addMouseTrackListener(new MouseTrackAdapter() {     
      public void mouseHover(MouseEvent event) {     
          Point pt = new Point(event.x, event.y);     
          int index = table.getTopIndex();     
          while (index < table.getItemCount()) {     
              TableItem item = table.getItem(index);     
              for (int i = 0; i < table.getColumnCount(); i++) {     
                  Rectangle rect = item.getBounds(i);     
                  if (rect.contains(pt)) {     
                      Object object= item.getData();     
                      //TODO 此處可以進行類型的轉(zhuǎn)化了   
                  }     
              }     
              index++;     
          }     
      }     
  });   
 
 4.指定JFace中Dialog初始化的位置 打開一個新的 對話框 時,如何設(shè)定它和父 對話框 的相對位置?比如在登錄 對話框 有一個“創(chuàng)建新賬號”的按鈕,用戶點擊以后,就出現(xiàn)新的對話框用于注冊,請問如何能讓新的 對話框 和舊 對話框 排列的整齊一些?應(yīng)該是能設(shè)定二者的相對位置吧?  
 
 
 protected Point getInitialLocation(Point initialSize) {     
        Point location = new Point(this.getParentShell().getLocation().x     
                + this.getParentShell().getBounds().width, this     
                .getParentShell().getLocation().y     
                + this.getParentShell().getBounds().height     
                - this.getInitialSize().y);     
        return location;     
    }    
 
 5.在RCP中使界面適合桌面大小 
 final int screenWidth = Display.getCurrent().getBounds().width; final int screenHeight = Display.getCurrent().getBounds().height; 
 6.在透視圖快捷方式欄中同時顯示多個透視圖快捷方式 
 如果在程序中用到了多個透視圖,默認(rèn)只顯示初始透視圖快捷方式,每次都要 打開透視圖——other,特麻煩,所以用戶可能希望以更加快捷的方式來打開透視圖,下面提供了2種方式: 第一種是在切換欄中顯示: 
 
 
 
 public class PIMWorkbenchAdvisor extends WorkbenchAdvisor {  
    @Override  
    public void postStartup() {  
        super.postStartup();  
        IWorkbenchWindow activeWorkbenchWindow PlatformUI.getWorkbench().getActiveWorkbenchWindow();  
        設(shè)置同時顯示多個透視圖標(biāo)  
        PerspectiveBarManager barManager =((WorkbenchWindow)activeWorkbenchWindow).getPerspectiveBar();  
        if(barManager != null){  
            IPerspectiveDescriptor mailPerspective = WorkbenchPlugin.getDefault().getPerspectiveRegistry   ().findPerspectiveWithId("MyWork_mail.perspective");  
            PerspectiveBarContributionItem item=new PerspectiveBarContributionItem(mailPerspective,activeWorkbenchWindow.getActivePage());  
            barManager.addItem(item);  
        }  
}  
 第二種是在下拉框中顯示: 
 
 
 public class UiPerspective implements IPerspectiveFactory  
{  
    public void createInitialLayout(IPageLayout layout){  
        //增加透視圖  
        layout.addPerspectiveShortcut("net.sf.pim.plugin.UiPerspective");  
        layout.addPerspectiveShortcut("MyWork_mail.perspective");  
       }  
}  
 
 7.控制文件菜單中“最近打開文檔”的個數(shù) RCP中在繼承ActionBarAdvisor的類中定義: 
 private IContributionItem reOpenAction = ContributionItemFactory.REOPEN_EDITORS.create(window); 然后在fillMenuBar(IMenuManager menuBar)方法中添加上面的aciton 
 運行時“最近打開的文檔”只有4個,如果想自己控制“最近打開的文檔”的數(shù)量,則設(shè)置一下Workbench中的初始化首選項時RECENT_FILES的默認(rèn)參數(shù)值如: WorkbenchPlugin.getDefault().getPreferenceStore().setDefault(IPreferenceConstants.RECENT_FILES,10); 
 8.設(shè)置透視圖工具欄的位置 在 Eclipse 中可以通過在首選項Window->Preferences-> Workbench->Appearance中來設(shè)置它顯示的位置,那么如何用程序來實現(xiàn)這已功能呢,需要在ApplicationWorkbenchAdvisor 類的 方法 initialize(IWorkbenchConfigurer configurer)中通過設(shè)置首選項的值來實現(xiàn): 
 // 保存當(dāng)前窗口狀態(tài) configurer.setSaveAndRestore(true); // 設(shè)備界面標(biāo)題風(fēng)格 PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,false); PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, IWorkbenchPreferenceConstants.TOP_RIGHT); | 
|  |