刷新表编辑器与swt中的表项

时间:2013-02-05 06:01:24

标签: java swt

您好我有以下swt表的代码

private Table   folderAssociationTable;
private TableItem            item;
private TableEditor          editor; 

folderAssociationTable = componentsRenderer.createTableWidget(container, SWT.BORDER | SWT.MULTI  | SWT.FULL_SELECTION, 2, true);

        folderAssociationTable.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height = 20;
            }
        });

        componentsRenderer.createTableColumWidget(folderAssociationTable, SWT.CHECK, "Item", 80);
        // add a column to display source folders
        componentsRenderer.createTableColumWidget(folderAssociationTable, 
                SWT.LEFT, PropertyClass.getPropertyLabel(QTLConstants.SOURCE_FOLDER_COLUMN_LABEL), 200);
        // add a column to display target folders
        componentsRenderer.createTableColumWidget(folderAssociationTable,
                SWT.LEFT, PropertyClass.getPropertyLabel(QTLConstants.TARGET_FOLDER_COLUMN_LABEL), 200);

然后以这种方式添加表格数据

item = new TableItem(folderAssociationTable, SWT.NONE);
                            editor = new TableEditor (folderAssociationTable);

                            Button button = new Button(folderAssociationTable, SWT.CHECK);
                            button.setText("item "+ (i+1));
                            button.pack();
                            editor.minimumWidth = button.getSize ().x;
                            editor.setEditor(button, item, 0);

                            item.setText(1, folderlist[i]);    // add source folder to the first column of the table
                            item.setText(2, targetFolderPath);  // add target folder to the second column of the table
                            sourceTargetFolderMap.put(folderlist[i], targetFolderPath); 

我在表组件外面的这个页面上有删除按钮,关于它的动作Listener我从表中删除了选定的行,但是在这种情况下当表更新时只有表项更新但表编辑器保持在同一位置,怎么能我点击删除按钮刷新表编辑器和表项。

1 个答案:

答案 0 :(得分:1)

你见过documentation给出的例子吗?将其添加到您的ActionListener

// to close the old editor
Control oldEditor = editor.getEditor();
if (oldEditor != null) oldEditor.dispose();

// add some logic if you want to open the editor again on a different row