Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable scrollbar in ScrolledForm?

ScrolledForm's scrollBar can sometimes cause problems.I meet the same problem with this guy in EclipseZone Forum (it's a question asked in 2005 but seems to be unresolved).

//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.

like image 924
Sam Su Avatar asked Jul 05 '13 09:07

Sam Su


1 Answers

I've come accross this issue several times and solved it like this:

@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);
        }
    });
}

Notice the GridLayout in the form's body and then setting the width and height hint to the composite's GridLayoutData.

Also notice the resize listener on the body which updates the grid layout data and layouts the composite.

Hope it helps!

like image 183
janhink Avatar answered Sep 30 '22 16:09

janhink