8

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

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

4

1 回答 1

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.

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

希望能帮助到你!

于 2014-07-10T12:04:05.777 回答