SWT TableColumn不起作用?

时间:2014-02-11 14:42:43

标签: java swt jface tablecolumn

有人可以解释我的代码有什么问题吗?  我想创建一个简单的swt表。

Eclipse注意到TableColumn未定义:

    TableColumn column = new TableColumn(table, SWT.NONE);

以下是完整的代码:

    Shell shell = new Shell();
    shell.setSize(280, 300);
    shell.setText("Testtabelle");

    Table table = new Table(shell, SWT.MULTI | SWT.BORDER
        | SWT.FULL_SELECTION);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] titles = { " ", "C", "!", "Description", "Resource", "In Folder", "Location" }; 
    for (int i = 0; i < titles.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(titles[i]);
    }

    int count = 128;
    for (int i = 0; i < count; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(0, "x");
      item.setText(1, "y");
      item.setText(2, "!");
      item.setText(3, "this stuff behaves the way I expect");
      item.setText(4, "almost everywhere");
      item.setText(5, "some.folder");
      item.setText(6, "line " + i + " in nowhere");
    }
    for (int i = 0; i < titles.length; i++) {
      table.getColumn(i).pack();
    }
    table.setSize(table.computeSize(SWT.DEFAULT, 200));
    shell.pack();
    shell.open();

1 个答案:

答案 0 :(得分:3)

确保导入正确的TableColumn。在您的情况下,这将是:

org.eclipse.swt.widgets.TableColumn

如果您不需要,请确保不导入任何其他TableColumn。一个流行的例子是:

javax.swing.table.TableColumn