Editable SWT Table

How to edit SWT table values ​​without using mouse listeners?

+3
source share
5 answers

Do the links TableEditorin the link below help ?

SWT fragments

In the first example, the section TableEditoruses the table SelectionListenerin the table (unlike the second example, which uses the MouseDown event that you mentioned, you don’t want to)

Perhaps you can also use TraverseListeneror KeyListenerto help you achieve what you want.

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

        }
    });     

tblProvision - . , . EDITABLECOLUMN. column, .

+4

JFace, SWT, JFace Snippets,

+1

, :

Table table = new Table(parent, SWT.NONE);
TableItem item = new TableItem(table, SWT.NONE);
item.setText("My new Text");
0
0
source

Source: https://habr.com/ru/post/1725840/


All Articles