Unable to set size for a scrolled composite SWT

422 views Asked by At

I have a main composite and within it two scrolled composites. The first scrolled composite does not have anything within it as of now. The second scrolled composite has a list. The problem is since that list is large, the second scrolled composite is occupying majority of the main composite area and leaves just a small square portion for the first scrolled composite. I want the two scrolled composite to be of at least equal sizes or one bigger than the other. I am not able to achieve this using the setSize() methods for the composites.

Code:

/** 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)); 

Kindly help. Thanks in advance.

1

There are 1 answers

0
Gregor Valentin On

Have you tried:

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 ;

and then

composite.setLayoutData(compositeData);

I had a similar problem and this worked for me.