2013-07-05 59 views
8

ScrolledForm的滾動條有時會​​導致問題。我遇到了與this guy in EclipseZone Forum相同的問題(這是2005年提出的一個問題,但似乎尚未解決)。如何禁用ScrolledForm中的滾動條?

//The scrollbar should only be displayed in the TreeViewer,not the whole form The scrollbar should only be displayed in the TreeViewer,not the whole form.

+1

所以不要使用滾動窗體。使用不同的容器。 – jarodeells

+1

@jarodeells這是因爲ManagedForm的方法'getForm()'返回一個ScrolledForm。(http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi% 2Forg%2Feclipse%2Fui%2Fforms%2FManagedForm.html) –

+1

你能用@ janhink的例子解決你的問題嗎?我有似乎是同樣的問題,但無法得到該解決方案的工作,所以你找到一個我很好奇它是如何工作的。 – NealSr

回答

3

我來翻過這一問題多次和解決它像這樣:

@Override 
protected void createFormContent(IManagedForm managedForm) { 
    // set the form's body's layout to GridLayout 
    final Composite body = managedForm.getForm().getBody(); 
    body.setLayout(new GridLayout()); 

    // create the composite which should not have the scrollbar and set its layout data 
    // to GridData with width and height hints equal to the size of the form's body 
    final Composite notScrolledComposite = managedForm.getToolkit().createComposite(body); 
    final GridData gdata = GridDataFactory.fillDefaults() 
      .grab(true, true) 
      .hint(body.getClientArea().width, body.getClientArea().height) 
      .create(); 
    notScrolledComposite.setLayoutData(gdata); 

    // add resize listener so the composite's width and height hints are updates when 
    // the form's body resizes 
    body.addControlListener(new ControlAdapter() { 
     @Override 
     public void controlResized(ControlEvent e) { 
      super.controlResized(e); 
      gdata.widthHint = body.getClientArea().width; 
      gdata.heightHint = body.getClientArea().height; 
      notScrolledComposite.layout(true); 
     } 
    }); 
} 

注意的GridLayout形式的身體,然後設置寬度和高度hint到複合材料的GridLayoutData

另請注意,在更新網格佈局數據和佈局複合體的正文上調整大小偵聽器。

希望它有幫助!

+0

感謝您的代碼示例。我試圖使用notScrolledComposite作爲我的SashForm的父組合,而不是刪除右側的滾動條,整個內部控件消失。當您使用此修復程序時,您是否需要做任何特別的事情? – NealSr

+0

您是否爲notScrolledComposite設置了合適的佈局? – janhink