Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editable SWT table

Tags:

swt

How to edit SWT table Values without Using Mouse Listeners?

like image 831
Palani Avatar asked Feb 04 '26 19:02

Palani


2 Answers

Do the TableEditor snippets in the below link help?

SWT Snippets

The first example in the TableEditor section uses a SelectionListener on the table (unlike the second example which uses a MouseDown event you mentioned you don't want)

You could perhaps make use of the TraverseListener or KeyListener too to help you achieve what you want.

like image 159
mecsco Avatar answered Feb 12 '26 13:02

mecsco


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

        }
    });     

Here tblProvision is the name of your table. you can just now edit Your table by clicking on it. I have Declare EDITABLECOLUMN. this is the column that u want to edit.

like image 26
Dinup Kandel Avatar answered Feb 12 '26 12:02

Dinup Kandel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!