[英]How to get the scrollbars to work in a ScrolledComposite when using GridLayout?
I am trying to have a scrolled composite with a fixed size content and a label below the scrolled composite display status information of the scrollable content. 我正在尝试使用具有固定大小内容的滚动复合内容,并在滚动复合内容的滚动复合显示状态信息下方添加一个标签。 As I want the controls to resize with the parent, I have used GridLayout on their parent.
因为我希望控件与父控件一起调整大小,所以我在其父控件上使用了GridLayout。 But I am facing an issue with the scroll bars of the scrolled composite and positioning of the label control.
但是我面临着滚动复合滚动条和标签控件位置的问题。 ie, the scrolling doesn't work unless I set the scrolledcomposite's grid data attribute as
即,除非将scrolledcomposite的网格数据属性设置为
grabExcessVerticalspace = true
If I allow the scrolledcomposite to grab the excess vertical space, the label does not appear below the scrolledcomposite due to the space between them. 如果我允许滚动复合材料抓住多余的垂直空间,则由于滚动复合材料之间的空间,标签不会出现在滚动复合材料下方。
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();
}
}
Any help in having the label appear exactly below the scrolled composite (trim the space) and have the scrolling work is appreciated. 对于使标签出现在滚动组合的正下方(修剪空间)并进行滚动工作的任何帮助,都将受到赞赏。
Edit: 编辑:
Expected behavior: 预期行为:
You need to set the layout data of the ScrolledComposite
to FILL
like so: 您需要像这样将
ScrolledComposite
的布局数据设置为FILL
:
new GridData( SWT.FILL, SWT.FILL, true, true );
This way, the ScrolledComposite will take the available space of the grid cell. 这样,ScrolledComposite将占用网格单元的可用空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.