我有一个水平ScrolledComposite
持有两个按钮(实际上是一个有两个按钮的复合材料)。即使滚动条被隐藏,滚动条的空间也会被分配。(当水平空间足够且不需要滚动时,它们会被隐藏。)
我怎样才能摆脱这个浪费的空间?
同时,我已将滚动合成配置为始终显示滚动条 ( setAlwaysShowScrollBars(true)
),但我更愿意摆脱浪费的空间。
谢谢您的考虑。
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ScrollbarSpaceIssue extends Composite
{
public ScrollbarSpaceIssue(final Composite parent, final int style)
{
super(parent, style);
setLayout(new GridLayout(1, false));
final ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.H_SCROLL);
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
//scrolledComposite.setAlwaysShowScrollBars(true);
{
final Composite composite = new Composite(scrolledComposite, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
{
final Button btn1 = new Button(composite, SWT.NONE);
btn1.setText("Button 1");
final Button btn2 = new Button(composite, SWT.NONE);
btn2.setText("Button 2");
}
scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
pack();
}
public static void main(final String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Testcase");
shell.setLayout(new FillLayout());
new ScrollbarSpaceIssue(shell, SWT.NONE);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}