因工作上的要求,要將sql運行后得結果集顯示到表格中去,在網上很難找到有類似的代碼。
以前做的,都是固定的列,用如下代碼即可:
但因為生成的列是不可以刪除的,再加就會有更多的列,感覺沒有辦法了,但其實還有有辦法的。象通過如下方式:
TableLayout tLayout = new TableLayout();
table.setLayout(tLayout);

String[] columns = new String[] { "列1", "列2", "列3" };

for (int i = 0; i < columns.length; i++) {
tLayout.addColumnData(new ColumnWeightData(100)); // 100個單位的寬度
new TableColumn(table, SWT.NONE).setText(columns[i]);
}
以前做的,都是固定的列,用如下代碼即可:
table = new Table(composite, SWT.BORDER);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10, 28, 367, 99);
final TableColumn Column_1 = new TableColumn(table, SWT.NONE);
Column_1.setWidth(120);
Column_1.setText("名稱");
final TableColumn Column_2 = new TableColumn(table, SWT.NONE);
Column_2.setWidth(100);
Column_2.setText("別名");
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10, 28, 367, 99);
final TableColumn Column_1 = new TableColumn(table, SWT.NONE);
Column_1.setWidth(120);
Column_1.setText("名稱");
final TableColumn Column_2 = new TableColumn(table, SWT.NONE);
Column_2.setWidth(100);
Column_2.setText("別名");
但因為生成的列是不可以刪除的,再加就會有更多的列,感覺沒有辦法了,但其實還有有辦法的。象通過如下方式:








