Q:

How to disable left and right arrow keys for navigation in SWT List?

The SWT List lets both left and up arrow keys to go up the list items and both right and down arrow keys to go down the list items by default. But I want to use left and right arrow keys for another propose. How can I remove the left and right arrow keys listener that is in SWT List by default? And then replace my own. Here is the code I want to use:
Listener listListener = new Listener() {
        public void handleEvent(Event e) {
            int RowIndex = listData.getSelectionIndex();

            if(RowIndex == 0){
                if (e.keyCode == SWT.ARROW_RIGHT) { //right arrow
                    //do something
                }else if (e.keyCode == SWT.ARROW_LEFT) { //left arrow
                    //do something
                }
             }
         }
    };
    list.addListener(SWT.KeyDown, listListener);

Thank you!

A:

You can suppress the default behavior of key strokes by setting the doit flag to false like this:
if( event.keyCode == SWT.ARROW_RIGHT ) {
  // do something    
  event.doit = false;
}

The default behavior of arrows keys is very likely platform dependant. Windows behaves as you describe, but other platforms might behave differently. Setting the doit flag to false will work in any case, whether the key has a default behavior or not.
I would rather not override platform behavior because your applications will then behave inconsistent with respect to the platforms general usage.

