Search code examples
javaeclipselayoutswtpreferences

Is it possible to use anything other than GridLayout on Eclipse preference pages?


The following simple preference page fails with a ClassCastException:

@Override
protected Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout());
    List list = new List(container, SWT.NONE);
    return container;
}

The same code works fine with a regular SWT application. If I replace the FillLayout with a GridLayout, it works, but that doesn't satisfy me. Is there no way to use a FillLayout or RowLayout in Eclipse preference pages?

Edit: I'm very sorry, I did not pay enough attention when preparing the example. The above code does indeed work fine. In my code, I returned the list, not the container (!). For some reason, that worked in normal SWT, but it's really nonsense.


Solution

  • Should be doable, maybe two tricks, one is to try this:

    container.setLayoutData(new GridData(...));
    

    And if that doesn't do the trick, then adding first one container with GridLayout and inside that FillOut should definatedly work.

    Bit strange anyhow, I would have assumed that code provided would have worked, but try setting that layoutdata.