以下代码片段在ScrolledComposite内部生成一个Composite。我也放了一个标签。垂直滚动条被滚动,表明合成物占据了太多空间。
@Override
public void createPartControl(Composite parent) {
if (this.parent == null) {
this.parent = parent;
}
parent.setLayout(new GridLayout());
SashForm mainComposite = new SashForm(parent, SWT.NONE);
mainComposite.setLayout(new GridLayout());
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
mainComposite.setLayoutData(gd);
// createLeftSide(mainComposite);
createRightSide(mainComposite);
// mainComposite.setWeights(new int[] { 1, 4 });
}
问题仅在createRightSide中出现:
private void createRightSide(Composite mainComposite) {
ScrolledComposite detailsSC = new ScrolledComposite(mainComposite, SWT.SMOOTH | SWT.BORDER);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
detailsSC.setLayoutData(gd);
detailsSC.setLayout(new GridLayout(1, true));
Composite detailsComposite = new Composite(detailsSC, SWT.V_SCROLL);
detailsComposite.setLayout(new GridLayout(2, false));
detailsSC.setContent(detailsComposite);
detailsSC.setExpandHorizontal(true);
detailsSC.setExpandVertical(true);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
detailsSC.setLayoutData(gd);
Label dmyLabel = new Label(detailsComposite, SWT.NONE);
GridData labelData = new GridData();
dmyLabel.setLayoutData(labelData);
dmyLabel.setText("Dummy");
当我不为SWT.FILL
使用mainComposite
时,子复合材料不会填充空间。
detailsComposite.getVerticalBar().setEnabled(false);
无效,detailsSC.getVerticalBar()
返回null;
如何告诉复合材料不要占用超过必要的空间?
答案 0 :(得分:1)
我不确定是否能够复制您的确切大小写,但对我来说似乎出现了滚动条,因为您将样式SWT.V_SCROLL
放在了detailsComposite
而不是{{ 1}}(ScrolledComposite
)。
也:
detailsSC
,而是将两次设置为detailsComposite
detailsSC
知道何时显示滚动条此代码应该有效:
ScrolledComposite