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?

flavio.donze
  • 6,077
  • 9
  • 41
  • 69
Samuel Lampa
  • 4,146
  • 4
  • 37
  • 62

2 Answers2

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());
Samuel Lampa
  • 4,146
  • 4
  • 37
  • 62
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.

the.duckman
  • 6,276
  • 3
  • 21
  • 21
  • 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. – Samuel Lampa Dec 22 '10 at 14:36