문제

Can someone explain what is wrong with my code ? I want to create a simple swt table.

Eclipse notice that TableColumn is undefined:

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

Here is the complete Code:

    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();
도움이 되었습니까?

해결책

Make sure that you import the correct TableColumn. In your case, this will be:

org.eclipse.swt.widgets.TableColumn

Also make sure that you don't import any other TableColumn if you don't need it. A popular example would be:

javax.swing.table.TableColumn
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top