0
ScrolledComposite
延伸Composite
。那么是否可以将Button
直接添加到滚动的复合材料中而不需要其他复合材料?是否可以直接将按钮添加到ScrolledComposite?
ScrolledComposite
延伸Composite
。那么是否可以将Button
直接添加到滚动的复合材料中而不需要其他复合材料?是否可以直接将按钮添加到ScrolledComposite?
当然这是可能的:
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Stackoverflow");
shell.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
Button button = new Button(sc, SWT.NONE);
button.setText("Hello! This is a button with a lot of text...");
sc.setContent(button);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(button.computeSize(SWT.DEFAULT, SWT.DEFAULT));
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
之前调整:
调整后:
只记得打电话ScrolledComposite#setContent(Control)
与Button
作为参数。
是。我忘了#setcontent。谢谢。 – Rajasekhar