无法设置滚动复合SWT的大小

时间:2015-06-11 07:37:52

标签: swt scrolledcomposite

我有一个主要复合材料,其中有两个滚动复合材料。第一个滚动的复合材料在其中没有任何内容。第二个滚动复合有一个列表。问题是由于该列表很大,第二个滚动复合材料占据了主要复合区域的大部分,并且只留下了第一个滚动复合材料的小方形部分。我希望两个滚动的复合材料至少大小相同或比另一个大。我无法使用复合材料的setSize()方法实现此目的。

代码:

/** The main composite */
Composite leftComposite = new Composite(sashFormLeftRight, SWT.BORDER);
GridData leftCompositeGD = new GridData(SWT.FILL, GridData.FILL, true, false);
leftComposite.setLayoutData(leftCompositeGD);
leftComposite.setLayout(new GridLayout(1, false));

/** The first scrolled composite. Its UI elements will be filled at a later stage based on user input */
ScrolledComposite scrolledComposite = new ScrolledComposite(leftComposite, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);

Composite composite = new Composite(scrolledComposite, SWT.BORDER);
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
scrolledComposite.setContent(composite);

composite.layout(true, true);
scrolledComposite.layout(true, true);
scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

/** The second scrolled composite. It has an inner composite which has a list of string names */
ScrolledComposite scrolledParamComposite = new ScrolledComposite(leftComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData scrolledParamCompositeGD = new GridData(SWT.FILL, GridData.FILL, true, true);
scrolledParamComposite.setLayoutData(scrolledParamCompositeGD);
scrolledParamComposite.setExpandHorizontal(true);
scrolledParamComposite.setExpandVertical(true);

Composite innerComp = new Composite(scrolledParamComposite, SWT.BORDER );
innerComp.setLayout(new GridLayout(1, true));

scrolledParamComposite.setContent(innerComp);       

/** List which fills the second scrolled composite */
List parametersListForEnv = new List(innerComp, SWT.BORDER);
ParameterName[] namesList = Types.ParameterName.values();
for (int i = 0; i < namesList.length; i++) {
    parametersListForEnv.add(namesList[i].name());
}   

innerComp.layout(true, true);
scrolledParamComposite.layout(true, true);      
scrolledParamComposite.setMinSize(innerComp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 

请帮助。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

你试过了吗?

GridData compositeData = new GridData(GridData.FILL, GridData.FILL, true, true);
compositeData.heightHint = // your preferred height or the height of the other composite ;
compositeData.minimumHeight = // your preferred minimum height or the height of the other composite ;

然后

composite.setLayoutData(compositeData);

我有类似的问题,这对我有用。