Jaime
Jaime

Reputation: 361

How can I make the columns fill all the table?

I have created a tableViewer that contains a table with two columns. The fact is that the two columns don´t fill all the table area and I want to create two columns with same proportions to fill it.

Code:

TableViewer viewer = new TableViewer(createProjectConfig, SWT.MULTI | SWT.H_SCROLL| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
TableViewerColumn viewerColumn1 = new TableViewerColumn(viewer, SWT.NONE);

Table createVariablesTable = viewer.getTable();
createVariablesTable.setLayoutData(new FormData());
createVariablesTable.setHeaderVisible(true);
createVariablesTable.setLinesVisible(true);

FormData createVariablesTableData = new FormData();
createVariablesTableData.left = new FormAttachment(selectProjectPathLabel, 0, SWT.LEFT);
createVariablesTableData.top = new FormAttachment(selectProjectPathLabel, 40, SWT.TOP);
createVariablesTableData.right = new FormAttachment(selectProjectPathButton,0,SWT.RIGHT);
createVariablesTableData.bottom = new FormAttachment(createProjectConfigButton,-10,SWT.TOP);
createVariablesTable.setLayoutData(createVariablesTableData);

TableColumn column = viewerColumn.getColumn();
column.setText("${Variable}");
column.setWidth(50);//Make this fill the half of the table
column.setResizable(true);
column.setMoveable(true);

TableColumn column1 = viewerColumn1.getColumn();
column1.setText("${AAA}");
column1.setWidth(50);//Make this fill the half of the table
column1.setResizable(true);
column1.setMoveable(true);

Image:

enter image description here

Upvotes: 0

Views: 665

Answers (1)

greg-449
greg-449

Reputation: 111142

You need to set a table layout for the table.

TableLayout tableLayout = new TableLayout();
createVariablesTable.setLayout(tableLayout);

Then for each column set a column weight:

tableLayout.addColumnData(new ColumnWeightData(50));

tableLayout.addColumnData(new ColumnWeightData(50));

Also remove the calls to column.setWidth(50)

Upvotes: 1

Related Questions