So here is a solution that I developed using a custom layout. It wraps another layout, but can bind computeSize to the width or height of the parent composite - basically only allowing scrolling in one direction (if there is an easier way to get ScrolledForm to do this, please let me know!).
There are some nasty reflective hacks that need to be applied when the computeSize and layout : protected methods
import java.lang.reflect.Method; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Layout; public class BoundedLayout extends Layout { protected Layout delegateLayout; protected Method computeSizeMethod; protected Method layoutMethod; protected boolean widthBound; public BoundedLayout(Layout delegateLayout, boolean widthBound) { setDelegateLayout(delegateLayout); this.widthBound = widthBound; } public Layout getDelegateLayout() { return delegateLayout; } public void setDelegateLayout(Layout delegateLayout) { this.delegateLayout = delegateLayout; try { computeSizeMethod = delegateLayout.getClass().getDeclaredMethod( "computeSize", Composite.class, int.class, int.class, boolean.class); computeSizeMethod.setAccessible(true); layoutMethod = delegateLayout.getClass().getDeclaredMethod( "layout", Composite.class, boolean.class); layoutMethod.setAccessible(true); } catch (Exception e) { throw new RuntimeException(e); } } @Override protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
source share