【发布时间】:2017-09-14 17:01:01
【问题描述】:
我想要一个ScrolledComposite,它的父级为GridLayout,但滚动条不显示,除非我使用FillLayout。我对FillLayout 的问题是它的孩子占据了可用空间的相等部分。
在我的情况下,有两个小部件,顶部的一个不应超过窗口的 1/4,ScrolledComposite 应占据剩余空间。但是,他们都占了一半。
有没有办法将GridLayout 与ScrolledComposite 一起使用,或者是否可以修改FillLayout 的行为?
这是我的代码:
private void initContent() {
//GridLayout shellLayout = new GridLayout();
//shellLayout.numColumns = 1;
//shellLayout.verticalSpacing = 10;
//shell.setLayout(shellLayout);
shell.setLayout(new FillLayout(SWT.VERTICAL));
searchComposite = new SearchComposite(shell, SWT.NONE);
searchComposite.getSearchButton().addListener(SWT.Selection, this);
ScrolledComposite scroll = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
scroll.setLayout(new GridLayout(1, true));
Composite scrollContent = new Composite(scroll, SWT.NONE);
scrollContent.setLayout(new GridLayout(1, true));
for (ChangeDescription description : getChanges(false)) {
ChangesComposite cc = new ChangesComposite(scrollContent, description);
}
scroll.setMinSize(scrollContent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scroll.setContent(scrollContent);
scroll.setExpandVertical(true);
scroll.setExpandHorizontal(true);
scroll.setAlwaysShowScrollBars(true);
}
【问题讨论】:
-
我也遇到了同样的问题,你找到解决办法了吗?
-
Steve K 的回答应该被接受:它工作正常。
标签: java swt scrolledcomposite