设置CheckboxTableViewer的标题

时间:2015-02-09 10:10:36

标签: java jface

CheckboxTableViewer允许创建一个核对清单。

但是我如何设置这样一个列的标题,因为列本身不是由TableColumn创建的。

    tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.SINGLE| SWT.BORDER | SWT.FULL_SELECTION);

    tableViewer.add(checkListNames.get(0));
    tableViewer.add(checkListNames.get(1));
    tableViewer.add(checkListNames.get(2));
    tableViewer.add(checkListNames.get(3));
    tableViewer.add(checkListNames.get(4));
    tableViewer.add(checkListNames.get(5));

    final Table table = tableViewer.getTable();

    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    System.out.println(table.getColumnCount()); // this returns a zero

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

1 个答案:

答案 0 :(得分:1)

您需要使用TableLayoutTableViewerColumn来定义列,以便设置标题文字。

最小代码为:

TableLayout layout = new TableLayout();

TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.LEAD);

col.getColumn().setText("Text");

layout.addColumnData(new ColumnWeightData(100));

table.setLayout(layout);
相关问题