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

  • SEARCH
  • Home
  • 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 6628755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:46+00:00 2026-05-25T22:09:46+00:00

I have a TableViewer and want the selection to go down one cell when

  • 0

I have a TableViewer and want the selection to go down one cell when I press the enter key, much like in MS Excel. I implemented my own CellNavigationStrategy with the following findSelectedCell.

public ViewerCell findSelectedCell(ColumnViewer viewer,
                            ViewerCell currentSelectedCell, Event event) {
                        if (event.type == ColumnViewerEditorActivationEvent.KEY_PRESSED) {
                            if (event.keyCode == SWT.CR
                                    || event.keyCode == SWT.KEYPAD_CR) {
                                ViewerCell nextCell = currentSelectedCell
                                        .getNeighbor(ViewerCell.BELOW, false);
                                return nextCell;
                            }
                        }
                        return null;
                    }

This works pretty well as long as I have ViewerCell.LEFT or ViewerCell.RIGHT.
When I try ViewerCell.ABOVE or ViewerCell.BELOW nextCell is actually set to the
cell above or below, but in the GUI the selection stays at currentSelectedCell.

The API-Documentation for findSelectedCell says:

Returns:

the cell which is highlighted next or null if the default
implementation is taken. E.g. it’s fairly impossible to react on
PAGE_DOWN requests

I do not understand what that sentence means. Can anyone exlain to me why it is not possible to set the selection to a cell below or above?

  • 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-05-25T22:09:46+00:00Added an answer on May 25, 2026 at 10:09 pm

    When I try ViewerCell.ABOVE or ViewerCell.BELOW nextCell is actually
    set to the cell above or below, but in the GUI the selection stays at
    currentSelectedCell.

    You have to explicitly set the current selection after the KEY_PRESSED event. Now there are two ways to do it.

    1. v.getTable().showColumn(v.getTable().getColumn(nextCell.getColumnIndex())); where is the table viewer object. Now this approach normally works with the simple keys like SWT.ARROW_DOWN, SWT.ARROW_UP etc. But carriage return i.e. SWT.CR usually has some special meaning like submitting a form, pressing a default button on the composite etc. I haven’t checked thoroughly but my gut feeling says it is handled by some other handler and hence you lose focus.
    2. For SWT.CR use this: v.getTable().setSelection(((TableItem)nextCell.getItem()));

    Also you have to override the CellNavigationStrategy.isNavigationEvent(), otherwise SWT.CR and SWT.KEYPAD_CR would be ignored. For example:

    @Override
    public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
        return event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR;
    }
    

    I do not understand what that sentence means.

    It means that if you are going to use the default implementation of CellNavigationStrategy, which is shipped with JFace then it is not possible to handle the SWT.PAGE_DOWN key press event. The reason is that it is not handled in CellNavigationStrategy.isNavigationEvent() (see its implementation for more details).


    See the full working code below:

    import org.eclipse.jface.viewers.*;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.*;
    
    public class CellNavTest {
        public CellNavTest(Shell shell)
        {
            final TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
            v.setContentProvider(new MyContentProvider());
    
            TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
            column.getColumn().setWidth(200);
            column.getColumn().setText("Givenname");
            column.getColumn().setMoveable(true);
            column.setLabelProvider(new ColumnLabelProvider() {
    
                public String getText(Object element) {
                    return ((Person) element).givenname;
                }
            });
    
            column = new TableViewerColumn(v, SWT.NONE);
            column.getColumn().setWidth(200);
            column.getColumn().setText("Surname");
            column.getColumn().setMoveable(true);
            column.setLabelProvider(new ColumnLabelProvider() {
    
                public String getText(Object element) {
                    return ((Person) element).surname;
                }
    
            });
    
            column = new TableViewerColumn(v, SWT.NONE);
            column.getColumn().setWidth(200);
            column.getColumn().setText("E-Mail");
            column.getColumn().setMoveable(true);
            column.setLabelProvider(new ColumnLabelProvider() {
    
                public String getText(Object element) {
                    return ((Person) element).email;
                }
    
            });
    
            CellNavigationStrategy naviStrat = new CellNavigationStrategy() 
            {
    
                @Override
                public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
                    return event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR;
                }
    
                public ViewerCell findSelectedCell(ColumnViewer viewer, ViewerCell currentSelectedCell, Event event)
                {
                    if (event.type == ColumnViewerEditorActivationEvent.KEY_PRESSED) {
                        if (event.keyCode == SWT.CR  || event.keyCode == SWT.KEYPAD_CR) 
                        {
                            ViewerCell nextCell = currentSelectedCell.getNeighbor(ViewerCell.BELOW, false);
                            if(nextCell != null) 
                            {
                                /*
                                 * START
                                 * Shows the column. If the column is already showing in the receiver, this method simply returns. 
                                 * Otherwise, the columns are scrolled until the column is visible. So when you press enter it will just
                                 * return the same column index and hence as per javadoc it will just return.
                                 */
                                //System.out.println(nextCell.getColumnIndex());
                                //v.getTable().showColumn(v.getTable().getColumn(nextCell.getColumnIndex()));
                                /*
                                 * END
                                 */
    
                                if(nextCell.getItem() instanceof TableItem)
                                    v.getTable().setSelection(((TableItem)nextCell.getItem()));
                            }
                            return nextCell;
                        }
                    }
                    return null;
                }
    
            };
    
            new TableViewerFocusCellManager(v, new FocusCellOwnerDrawHighlighter(v), naviStrat);    
    
            Person[] model = createModel();
            v.setInput(model);
            v.getTable().setLinesVisible(true);
            v.getTable().setHeaderVisible(true);
        }
    
        private Person[] createModel() {
            Person[] elements = new Person[4];
            elements[0] = new Person("Tom", "Schindl",
                    "tom.schindl@bestsolution.at", "M");
            elements[1] = new Person("Boris", "Bokowski",
                    "Boris_Bokowski@ca.ibm.com","M");
            elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com","M");
            elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org","M");
    
            return elements;
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Display display = new Display();
    
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            new CellNavTest(shell);
            shell.open();
    
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
    
            display.dispose();
    
        }
    }
    
    class MyContentProvider implements IStructuredContentProvider {
    
        public Object[] getElements(Object inputElement) {
            return (Person[]) inputElement;
        }
        public void dispose() {
        }
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    }
    
    class Person {
        public String givenname;
        public String surname;
        public String email;
        public String gender;
        public Person(String givenname, String surname, String email, String gender) {
            this.givenname = givenname;
            this.surname = surname;
            this.email = email;
            this.gender = gender;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Table with checkboxes. I want to change the selection of the
I have a UINavigationController consisting of a tableview I want to load some data
In my application, I want to append cells to the current tableview and have
I have built a simple Eclipse plugin where a user may use a TableViewer
I have a tableView and when the user is selecting one of the cells,
I have a strange problem with UITableView and UITextField inside the cell (as subview).
Feel like I'm going a bit nutty here. I have a detail view with
i have made one list of images + respective data in tableview. it takes
I have an iPhone app based on a tabBar and tableViews. I want the
I have a UITableView and I want some cells to be the standard UITableViewCells

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.