如何在ScrolledForm中禁用滚动条?

时间:2013-07-05 09:20:28

标签: java swt jface eclipse-plugin

ScrolledForm的scrollBar有时会导致问题。我遇到this guy in EclipseZone Forum同样的问题(这是2005年提出的一个问题,但似乎没有得到解决)。

//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 个答案:

答案 0 :(得分: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

还要注意身体上的调整大小侦听器,它会更新网格布局数据并布局复合。

希望它有所帮助!

相关问题