如何将ScrollComposite放在SWT中的另一个ScrollComposite中。 我用两个scrollcomposite。第一个ScrollComposite包含多个ScrollComposite。每个儿童综合大小相等。因此,如果子ScrollComposite包含长度大于固定大小的小部件,则它滚动(每个子ScrollComposite根据包含小部件滚动),而父scrollComposite是子复合的滚动超过它的长度。
//这是我的代码
final Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout(SWT.VERTICAL));
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//First Scroll Composite
final ScrolledComposite scrolledComposite = new ScrolledComposite(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
cmpNotificationBody = new Composite(scrolledComposite, SWT.NONE);
cmpNotificationBody.setLayout(new FillLayout(SWT.VERTICAL));
//Second Scroll Composite
final ScrolledComposite scrolledComposite2 = new ScrolledComposite(cmpNotificationBody, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
scrolledComposite2.setExpandHorizontal(true);
scrolledComposite2.setExpandVertical(true);
cmpNotificationBody2 = new Composite(scrolledComposite2, SWT.NONE);
//do child GUI
//Make Scroll Composite Scrollable
scrolledComposite2.setContent(cmpNotificationBody2);
scrolledComposite2.setMinSize(
cmpNotificationBody2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
cmpNotificationBody2.layout();
scrolledComposite.setContent(cmpNotificationBody);
scrolledComposite.setMinSize(
cmpNotificationBody.computeSize(1,1);
cmpNotificationBody.layout();
答案 0 :(得分:2)
你应该试试这个
final Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout(SWT.VERTICAL));
container.setLayoutData(new GridData(GridData.FILL_BOTH));
final ScrolledComposite scrolledComposite = new ScrolledComposite(container, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
cmpNotificationBody = new Composite(scrolledComposite, SWT.NONE);
cmpNotificationBody.setLayout(new GridLayout(1, true));
scrolledComposite.setContent(cmpNotificationBody);
final Composite scrollParent = new Composite(cmpNotificationBody, SWT.NONE);
final GridData data = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1);
data.heightHint = 100;
scrollParent.setLayoutData(data);
scrollParent.setLayout(new FillLayout(SWT.VERTICAL));
final ScrolledComposite scrollCmp = new ScrolledComposite(scrollParent, SWT.H_SCROLL | SWT.V_SCROLL);
scrollCmp.setExpandHorizontal(true);
scrollCmp.setExpandVertical(true);
final Composite cmpBody = new Composite(scrollCmp, SWT.NONE);
scrollCmp.setContent(cmpBody);
final FillLayout layout = new FillLayout(SWT.VERTICAL);
layout.spacing = 10;
cmpBody.setLayout(layout);
//make GUI
scrollCmp.setContent(cmpBody);
scrollCmp.setMinSize(cmpBody.computeSize(SWT.DEFAULT, SWT.DEFAULT));
cmpBody.layout();
scrolledComposite.setContent(cmpNotificationBody);
scrolledComposite.setMinSize(cmpNotificationBody.computeSize(SWT.DEFAULT, SWT.DEFAULT));
cmpNotificationBody.layout();