Here is an example of using a TableEditor:
final Table table = new Table(shell, SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
TableColumn column1 = new TableColumn(table, SWT.NONE);
TableColumn column2 = new TableColumn(table, SWT.NONE);
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] {"item " + i, "edit this value"});
}
column1.pack();
column2.pack();
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 e) {
Text text = (Text)editor.getEditor();
editor.getItem().setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv ControlListener | |
| pack-priv TableItem | |
| pack-priv Table | |
| pack-priv static final int | |
| pack-priv Runnable |
| Access | Constructor and Description |
|---|---|
| public | TableEditor(Table
the Table Control above which this editor will be displayed table)Creates a TableEditor for the specified Table. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv Rectangle | |
| public void | dispose()
Overrides org. |
| public int | Returns: the zero based index of the column of the cell being tracked by this editorReturns the zero based index of the column of the cell being tracked by this editor. |
| public TableItem | Returns: the TableItem for the row of the cell being tracked by this editorReturns the TableItem for the row of the cell being tracked by this editor. |
| public void | layout()
Overrides org. |
| pack-priv void | |
| public void | setColumn(int
the zero based index of the column of the cell being tracked by this editor column)Sets the zero based index of the column of the cell being tracked by this editor. |
| public void | |
| public void | setEditor(Control
the Control that is displayed above the cell being edited editor, TableItem the TableItem for the row of the cell being tracked by this editor item, int the zero based index of the column of the cell being tracked by this editor column)Specify the Control that is to be displayed and the cell in the table that it is to be positioned above. |
| public void |
| column | back to summary |
|---|---|
| pack-priv int column | |
| columnListener | back to summary |
|---|---|
| pack-priv ControlListener columnListener | |
| item | back to summary |
|---|---|
| pack-priv TableItem item | |
| table | back to summary |
|---|---|
| pack-priv Table table | |
| TIMEOUT | back to summary |
|---|---|
| pack-priv static final int TIMEOUT | |
| timer | back to summary |
|---|---|
| pack-priv Runnable timer | |
| TableEditor | back to summary |
|---|---|
| public TableEditor(Table table) Creates a TableEditor for the specified Table.
| |
| computeBounds | back to summary |
|---|---|
| pack-priv Rectangle computeBounds() Overrides org.
| |
| dispose | back to summary |
|---|---|
| public void dispose() Overrides org. Removes all associations between the TableEditor and the cell in the table. The Table and the editor Control are not disposed.
| |
| getColumn | back to summary |
|---|---|
| public int getColumn() Returns the zero based index of the column of the cell being tracked by this editor.
| |
| getItem | back to summary |
|---|---|
| public TableItem getItem() Returns the TableItem for the row of the cell being tracked by this editor.
| |
| layout | back to summary |
|---|---|
| public void layout() Overrides org. Doc from org. Lays out the control within the underlying composite. This method should be called after changing one or more fields to force the Editor to resize.
| |
| resize | back to summary |
|---|---|
| pack-priv void resize() | |
| setColumn | back to summary |
|---|---|
| public void setColumn(int column) Sets the zero based index of the column of the cell being tracked by this editor.
| |
| setEditor | back to summary |
|---|---|
| public void setEditor(Control editor) Overrides org. Doc from org. Specify the Control that is to be displayed. Note The Control provided as the editor must be created with its parent being the Composite specified in the ControlEditor constructor. | |
| setEditor | back to summary |
|---|---|
| public void setEditor(Control editor, TableItem item, int column) Specify the Control that is to be displayed and the cell in the table that it is to be positioned above. Note The Control provided as the editor must be created with its parent being the Table control specified in the TableEditor constructor. | |
| setItem | back to summary |
|---|---|
| public void setItem(TableItem item) Specifies the
| |