可编辑的SWT表

Pal*_*ami 3 swt

如何在不使用鼠标侦听器的情况下编辑SWT表值?

小智 7

TableEditor以下链接中的片段有用吗?

SWT Snippets

TableEditor节中的第一个示例使用了一个SelectionListener表(与第二个示例不同,后者使用了您不想要的MouseDown事件)

也许你可以利用的TraverseListenerKeyListener过于帮助你实现你想要的.


Din*_*del 5

    final int EDITABLECOLUMN = 1;
tblProvisionInfo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Clean up any previous editor control
            final TableEditor editor = new TableEditor(tblProvisionInfo);               
            // The editor must have the same size as the cell and must
            // not be any smaller than 50 pixels.
            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;
            editor.minimumWidth = 50;
            Control oldEditor = editor.getEditor();
            if (oldEditor != null)
                oldEditor.dispose();                

            // Identify the selected row
            TableItem item = (TableItem) e.item;
            if (item == null)
                return;

            // The control that will be the editor must be a child of the
            // Table
            Text newEditor = new Text(tblProvisionInfo, SWT.NONE);
            newEditor.setText(item.getText(EDITABLECOLUMN));

            newEditor.addModifyListener(new ModifyListener() {
                public void modifyText(ModifyEvent me) {
                    Text text = (Text) editor.getEditor();
                    editor.getItem()
                            .setText(EDITABLECOLUMN, text.getText());
                }
            });         
            newEditor.selectAll();
            newEditor.setFocus();           
            editor.setEditor(newEditor, item, EDITABLECOLUMN);      

        }
    });     
Run Code Online (Sandbox Code Playgroud)

tblProvision是您的表的名称。您现在可以通过单击来编辑您的表格。我有声明EDITABLECOLUMN。这是column 你要编辑的。