3

Using the WindowBuilder for Eclipse, I have created a TableViewer which I have placed inside a composite. (The TableViewer creates an SWT Table, in which the TableViewer itself is inserted).

I have tried to make the composite resizable by setting grabExcessHorizontalSpace and grabVerticalSpace to true, but how to I make also the table and the TableViewer fill the composite?

2 Answers 2

4

I got the answer now, (Big thanks to rcjsuen on the #eclipse channel on irc.freenode.net).

The code I had looked like this: Composite comp = new Composite(container, SWT.NONE); comp.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));

What I needed to do was, in addition to setting grabExcessiveHorizontalSpace and grabExcessiveVerticalSpace to true, (param 3 and 4 in the setLayoutData() function), to set param 1 and 2 to SWT.FILL, and also add a FillLayout object with the setLayout() function, like so:

    Composite comp = new Composite(container, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    comp.setLayout(new FillLayout());
3

Hard to tell without code, but from your description you don't set a layout on your Composite. Try adding composite.setLayout(new FillLayout()); if your composite contains only the TableViewer.

If your composite has more than one child, you'll need a different layout, like GridLayout, or MigLayout. Then you'll also have to set layoutData on your Table and the other children of your composite.

Here are some snippets, which show how to use GridLayout. To learn MigLayout, which I find way better, see here.

1
  • Thanks! Yes, this was part of the solution. In addition, I also had to set SWT.FILL instead of SWT.LEFT and SWT.TOP in the setLayoutData(). I just solved this with help from #eclipse IRC channel, as documented in a separate answer. Dec 22, 2010 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.