TableViewer.refresh无法正常工作

时间:2014-12-12 20:17:48

标签: java eclipse eclipse-plugin

我添加到表格查看器的两个事件没有出现在屏幕上。

这是我创建表查看器,表和一列

的代码
    TableViewer tableViewer = new TableViewer(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    fd_btnNewButton.left = new FormAttachment(table, 6);
    FormData fd_table = new FormData();
    fd_table.top = new FormAttachment(eventLabel, 6);
    fd_table.left = new FormAttachment(0, 10);
    fd_table.right = new FormAttachment(100, -100);
    fd_table.bottom = new FormAttachment(eventLabel, 387, SWT.BOTTOM);
    table.setLayoutData(fd_table);
    TableColumn tableColumn = new TableColumn(table,SWT.LEFT);
    String[] column_names = new String[]{"Events"};
    tableColumn.setText(column_names[0]);
    tableViewer.setColumnProperties(column_names);
    tableViewer.setLabelProvider(new ContinuousIntegrationLabelProvider());
    tableViewer.setContentProvider(new ContinuousIntegrationContentProvider());

正在成功创建表..接下来,我正在设置输入,然后刷新表...

    events.add("Build"); //events is an ArrayList<String>
    events.add("JUnit Tests");
    tableViewer.setInput(events);
    tableViewer.refresh();

这是我的提供者方法:

/**
 * label provider for the table
 */ 
public class ContinuousIntegrationLabelProvider extends LabelProvider implements ITableLabelProvider {

    /**
     * image for the column
     */
    public Image getColumnImage(Object element, int index){
        switch(index){
            case 0:
                if(model.getJenkinsJob() == null){
                    return Images.getImage(Images.WARNING);
                }
                else{
                    return null;
                }
            default:
                return null;
        }
    }

    /**
     * returns the correct value for each column
     */
    public String getColumnText(Object element, int index){
        switch(index){
            case 0:
                return (String) element;
            default:
                return "";
        }
    }

这是我的内容提供商:

/**
 * content provider for the table
 */
public class ContinuousIntegrationContentProvider implements IStructuredContentProvider {

    @SuppressWarnings("unchecked")
    public Object[] getElements(Object inputElement) {
        ArrayList<String> data = (ArrayList<String>) inputElement;
        return data.toArray();
    }

    public void dispose() {
    }

    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    }

}

1 个答案:

答案 0 :(得分:0)

我只需要在表格列上设置宽度,然后一切都会显示出来。

以下是我更改的代码部分:

    TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
    String[] column_names = new String[]{"Events"};
    tableColumn.setText(column_names[0]);
    tableColumn.setWidth(352);