在以swt格式提交的多行文本上使用Tab键?
如何防止多行文本字段窃取" Tab键?
How do I prevent a multi-line text field from "stealing" tab-key presses?
我的意思是:我想使用TAB在窗口的各个元素之间循环,但是当我输入多行文本时,TAB成为普通"键,只需在我输入的文本中插入制表符即可.
I mean: I'd like to use TAB to cycle between the elements of a window, but when I enter the multiline text, TAB becomes a "normal" key, and simply inserts tabulators into the text I'm typing.
我该如何处理?我应该编写一些自定义侦听器,还是可以使用SWT常量更改组件的行为?
How do I handle this? Should I write some custom listener, or can I change the behaviour of the component by using an SWT constant?
SWT定义了一种使用TraverseListener类实现此类行为的机制.以下代码段(摘自
SWT defines a mechanism for implementing this kind of behaviour using the TraverseListener class. The following snippet (taken from here) shows how:
Text text1 = new Text(shell, SWT.MULTI | SWT.WRAP);
text1.setBounds(10,10,150,50);
text1.setText("Tab will traverse out from here.");
text1.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = true;
}
}
});