Reputation: 127
I have a composite and want to add a table to it. So far so good, but the table has in the beginning no input, so only the header appears on the composite. But I want the table to have a default (minimum) height (width should be managed by the GridLayout of the composite). The composite grabs the vertical and horizontal space of its parent so there should be enough space for the table. I add the table like this:
//comp is my composite
TableViewer viewer = new TableViewer(comp);
viewer.getTable().setHeaderVisible(true);
//Add two TableViewerColumns
//300 should be the minimum / default height
viewer.computeSize(SWT.DEFAULT, 300);
There is nothing else added to the composite and the composite seems to grab all the empty space from its parent but the table does not expand to a height of 300 (width is correct!).
I hope you can understand my problem:)
Upvotes: 1
Views: 2333
Reputation: 30089
computeSize returns a Point, which represents the preferred size of the table - this does not actually set the size of the component as the layout can ignore the preferred size
If you want an absolute fixed height for a table, you can do this by setting the table's parent to use the GridLayout layout, and then configure a GridData for the table:
comp.setLayout(new GridData());
gridData = new GridData();
gridData.heightHint = 300;
viewer.getTable().setLayoutData(gridData);
Upvotes: 4