JFace PreferencePage List with scrollbars

294 views Asked by At

i am trying to create a PreferencePage which holds a List. The List can get large and under the List there Buttons which interact with the List. It would be useful if the Buttons where always visible but when the list gets to large the PreferencePage is auto-expanding with scrollbars. enter image description here

My solution for now is a ScrolledComposite which holds the List. The Problem is that the ScrolledComposite is not filling out the layout. I have to set the size manually via setSize.

SWT.DEFAULT for hight: SWT.DEFAULT for hight

425 for height:

enter image description here

Code for ScrolledComposite with the List:

ScrolledComposite scroll = new ScrolledComposite(
            comp,
            SWT.H_SCROLL | SWT.V_SCROLL);


    Composite composite = new Composite(scroll, SWT.NONE);
    scroll.setContent(composite);
    scroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,true,2,1));

    GridLayout layout = new GridLayout(1, true);
    composite.setLayout(layout);

    List list = new List(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    GridData grid = new GridData(SWT.FILL, SWT.FILL, true, true);
    grid.horizontalSpan=1;
    list.setLayoutData(grid);

    scroll.setExpandHorizontal(true);
    composite.setSize(composite.computeSize(SWT.DEFAULT, 425));

The question is how can i make the ScrolledComposite to fill out the Layout without setting the hight value manually or prevent the PreferncePage from auto expanding. Using a table is also auto-expanding the hole PreferencePage. Setting scroll.setExpandVertical(true) also creates scrollbars on the PreferencePage and the List expands.

1

There are 1 answers

0
greg-449 On BEST ANSWER

Use the heightHint value of GridData to specify the height of the list. Since the preference page always tries to size the page to the full size of the controls it is necessary to set the height somewhere:

List list = new List(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData grid = new GridData(SWT.FILL, SWT.FILL, true, true);

grid.heightHint = 425;

list.setLayoutData(grid);