ScrolledComposite
扩展了Composite
。那么是否可以直接将 Button
添加到滚动的复合 Material 中,而无需在其中添加其他复合 Material ?
最佳答案
当然有可能:
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();
}
调整大小之前:
调整大小后:
只需记住以 Button
作为参数调用 ScrolledComposite#setContent(Control)
即可。
关于java - 是否可以直接将 Button 添加到 ScrolledComposite 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38232256/