[英]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. 在
SWT List
让两个left
和up
箭头键上去列表项和双方right
和down
箭头键在默认情况下下井列表项。 But I want to use left
and right
arrow keys for another propose. 但是我想使用
left
和right
箭头键进行其他提议。 How can I remove the left
and right
arrow keys listener that is in SWT List
by default? 我怎样才能去除
left
和right
箭头键监听器是在SWT List
默认? 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! 谢谢!
You can suppress the default behavior of key strokes by setting the doit
flag to false
like this: 您可以通过将
doit
标志设置为false
来抑制按键的默认行为 ,如下所示:
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.
Windows的行为与您描述的相同,但其他平台的行为可能有所不同。 Setting the
doit
flag to false
will work in any case, whether the key has a default behavior or not. 无论密钥是否具有默认行为,将
doit
标志设置为false
都将起作用。
I would rather not override platform behavior because your applications will then behave inconsistent with respect to the platforms general usage. 我宁愿不重写平台行为,因为您的应用程序的行为将与平台的一般用法不一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.