如何让列填满所有 table?
How can I make the columns fill all the table?
我创建了一个 tableViewer,其中包含一个 table 和两列。事实是这两列没有填满所有 table 区域,我想创建两列相同比例的列来填充它。
代码:
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);
图片:
您需要为table设置table布局。
TableLayout tableLayout = new TableLayout();
createVariablesTable.setLayout(tableLayout);
然后为每一列设置一个列权重:
tableLayout.addColumnData(new ColumnWeightData(50));
tableLayout.addColumnData(new ColumnWeightData(50));
同时删除对 column.setWidth(50)
的调用
我创建了一个 tableViewer,其中包含一个 table 和两列。事实是这两列没有填满所有 table 区域,我想创建两列相同比例的列来填充它。
代码:
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);
图片:
您需要为table设置table布局。
TableLayout tableLayout = new TableLayout();
createVariablesTable.setLayout(tableLayout);
然后为每一列设置一个列权重:
tableLayout.addColumnData(new ColumnWeightData(50));
tableLayout.addColumnData(new ColumnWeightData(50));
同时删除对 column.setWidth(50)