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 th开发者_开发百科e composite resizable by setting grabExcessHorizontalSpace
and grabVerticalSpace
to true, but how to I make also the table and the TableViewer
fill the composite?
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());
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.
精彩评论