如何在ScrolledForm中禁用滚动条?

Sam*_* Su 8 java swt eclipse-plugin jface

ScrolledForm滚动条有时会​​导致问题.我在EclipseZone论坛中遇到了同样的问题(这是2005年提出的一个问题,但似乎尚未解决).

//The scrollbar should only be displayed in the TreeViewer,not the whole form 滚动条应仅显示在TreeViewer中,而不是整个表单中.

jan*_*ink 4

我已经多次遇到这个问题并解决了,如下所示:

@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);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

请注意GridLayout表单主体中的 ,然后将宽度和高度设置hint为复合材料的GridLayoutData

另请注意主体上的调整大小侦听器,它更新网格布局数据并布局组合。

希望能帮助到你!