是否可以直接将 Button 添加到 ScrolledComposite?

Is it possible to add a Button to a ScrolledComposite directly?

ScrolledComposite 扩展 Composite。那么是否可以直接将 Button 添加到滚动的复合中而不需要另一个复合?

当然有可能:

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Whosebug");
    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();
}

调整大小前:

调整大小后:

记得用Button作为参数调用ScrolledComposite#setContent(Control)