【发布时间】:2016-09-13 06:58:48
【问题描述】:
我正在尝试让滚动合成具有固定大小的内容和可滚动内容的滚动合成显示状态信息下方的标签。由于我希望控件与父级一起调整大小,因此我在其父级上使用了 GridLayout。但是我遇到了滚动复合的滚动条和标签控件的定位问题。即,除非我将 scrolledcomposite 的网格数据属性设置为
,否则滚动不起作用grabExcessVerticalspace = true
如果我允许 scrolledcomposite 抓取多余的垂直空间,由于它们之间的空间,标签不会出现在 scrolledcomposite 下方。
public class Snippet5 {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
// this button is always 400 x 400. Scrollbars appear if the window is
// resized to be too small to show part of the button
ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
Button b1 = new Button(c1, SWT.PUSH);
b1.setText("fixed size button");
b1.setSize(400, 400);
c1.setAlwaysShowScrollBars(true);
c1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
c1.setContent(b1);
Label l = new Label(shell, SWT.BORDER);
l.setText("button clicked");
GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, false);
layoutData.heightHint = 30;
layoutData.widthHint = 400;
l.setLayoutData(layoutData);
shell.setSize(600, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
感谢任何帮助使标签恰好出现在滚动合成下方(修剪空间)并进行滚动工作。
编辑:
预期行为:
- 要被标签抓住的额外垂直空间。
- 在调整外壳大小时无法完全查看内容时,滚动复合应启用垂直滚动。
【问题讨论】:
标签: java swt grid-layout scrolledcomposite