使用 swt 中的表格项目刷新表格编辑器 [英] Refreshing table Editor with table item in swt

查看:46
本文介绍了使用 swt 中的表格项目刷新表格编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有以下 swt 表代码

Hello i have a following code for swt table

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);

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

and then adding table data in this fashion

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); 

我在表格组件外的这个页面上有删除按钮,在它的动作监听器上我从表格中删除选定的行,但在这种情况下,当表格更新时,只有表格项目被更新,但表格编辑器保持在同一位置,如何才能单击删除按钮,我刷新了表格编辑器和表格项目.

I have remove button on this page outside table component , on its action Listener i am removing selected row from table , but in this case when table is getting updated only table items are updated but table editor remain at same position , how can i refresh both table editor and table items on click of remove button.

推荐答案

您是否看过 文档?将此添加到您的 ActionListener:

Have you seen the example given in the documentation? Add this to your 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

这篇关于使用 swt 中的表格项目刷新表格编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆