2013-07-05 57 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