简体   繁体   中英

Make a JFace TableViewer resize with it's surrounding composite?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM