How to disable scrollbar in ScrolledForm?
Asked Answered
M

1

8

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.

Minier answered 5/7, 2013 at 9:20 Comment(3)
So don't use a scrolledform. Use a different container.Delores
@Delores that's because ManagedForm's method getForm() return a ScrolledForm.(help.eclipse.org/indigo/…)Minier
were you able to solve your issue with @janhink's example? I have what appears to be the same issue but am unable to get that solution to work, so it you found one that does I'm curious what it took to get it working.Desiccated
O
4

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!

Oxbridge answered 10/7, 2014 at 12:4 Comment(2)
Thank you for your code sample. I tried to use the notScrolledComposite as the parent Composite for my SashForm and instead of removing the scrollbar on the right, the entire inner control disappears. Did you need to do anything special when you used this fix?Desiccated
Have you set a suitable layout to the notScrolledComposite?Oxbridge

© 2022 - 2024 — McMap. All rights reserved.