Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:47:03+00:00 2026-06-16T15:47:03+00:00

Is it possible to change the default behavior of SWT/JFace to enable cell editing

  • 0

Is it possible to change the default behavior of SWT/JFace to enable cell editing only with double clicking? The way it is now (with single click) is hard to select a table row without bringing the text field up.

Here is a self-contained code snippet:

package table.editing;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

public class TableEditor extends ApplicationWindow {

    class Element {
        private String value;

        public Element(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public TableEditor() {
        super(null);

        setBlockOnOpen(true);
        open();

        Display.getCurrent().dispose();
    }

    protected Control createContents(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new FillLayout());

        TableViewer viewer = new TableViewer(composite, SWT.MULTI
                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

        createColumns(composite, viewer);
        addElements(viewer);

        final Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        return composite;
    }

    private void addElements(TableViewer viewer) {
        for (int i = 0; i < 10; i++) {
            viewer.add(new Element("Element " + i));
        }
    }

    private void createColumns(Composite parent, final TableViewer viewer) {
        TableViewerColumn columnViewer = new TableViewerColumn(viewer, SWT.NONE);
        columnViewer.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                Element element = (Element) cell.getElement();
                cell.setText(element.getValue());
            }
        });
        columnViewer.setEditingSupport(new EditingSupport(viewer) {

            @Override
            protected void setValue(Object element, Object value) {
                ((Element) element).setValue((String) value);
            }

            @Override
            protected Object getValue(Object element) {
                return ((Element) element).getValue();
            }

            @Override
            protected CellEditor getCellEditor(Object element) {
                return new TextCellEditor(viewer.getTable());
            }

            @Override
            protected boolean canEdit(Object element) {
                return true;
            }
        });
        TableColumn column = columnViewer.getColumn();
        column.setText("Example");
        column.pack();
    }

    public static void main(String[] args) {
        new TableEditor();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:47:04+00:00Added an answer on June 16, 2026 at 3:47 pm

    You need to set your own TableViewerEditor on the TableViewer. Have a look at the code below:

    TableViewer viewer = ...
    
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer));
    
    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            // Enable editor only with mouse double click
            if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
                EventObject source = event.sourceEvent;
                if (source instanceof MouseEvent && ((MouseEvent)source).button == 3)
                    return false;
    
                return true;
            }
    
            return false;
        }
    };
    
    TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL | 
        ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | 
        ColumnViewerEditor.TABBING_VERTICAL |
        ColumnViewerEditor.KEYBOARD_ACTIVATION);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change the default behavior of form elements in CakePHP without
Is it possible to change the default text (something like looking for other iPhones
Is it possible to change the default background colour of black in Silverlight Encoder
I'm trying to know whether it is possible to change the default android OS
In Ruby on Rails, is it possible to change a default action for a
Good Afternoon! Has anybody else noticed a change in the default behavior of the
According to the documentation there are only two ways to change the default logging
I have a div with the 'resize' property. By default, you can only change
Is it possible to change the default separator when cast (dcast) assigns new column
I want to change the default behavior for the jquery.validate.unobtrusive.js I want to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.