[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: TableEditor === Character editor?

Why do set the items text on modify? It is enough to do it when the focus is lost. I can't see any problem in your code maybe you could provide a completely runnable snippet or even better:

I'd advise you to use a JFace-Viewer with EditingSupport.

Tom

Robert B schrieb:
Hi,

I have implemented the following TableEditor. It works but
it turned out to be character editor, meaning each character typing,
editors disappears. I cannot type words continuously!
I am not sure there's better way than this!

========================================
 final TableEditor editor = new TableEditor(table);
 //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;
 // editing the second column
 final int EDITABLECOLUMN = 1;

 table.addSelectionListener(new SelectionAdapter() {
  public void widgetSelected(SelectionEvent e) {
   // Clean up any previous editor control
   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(table, 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);
  }
 });




--
B e s t S o l u t i o n . at
--------------------------------------------------------------------
Tom Schindl                                          JFace-Committer
--------------------------------------------------------------------