我正在使用Eclipse和SWT编写用于数据输入的Java应用程序。当然它有很多Text对象。
我想要发生的是,当用户在一个字段中输入内容时,焦点会自动切换到下一个字段。
提前致谢
答案 0 :(得分:2)
final Text textBox = new Text(shell, SWT.NONE);
textBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (x.getText().length() == 1); {
x.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}
});
答案 1 :(得分:1)
final Text textBox = new Text(shell, SWT.NONE);
textBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if (textBox.getText().equals("") == false) {
textBox.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}});
答案 2 :(得分:1)
您可能还想查看VerifyListener接口。请参阅这篇有趣的博客文章,但需要注意:http://eclipsenuggets.blogspot.com/2008/10/eclipse-bug-patterns-selfish-validation.html
答案 3 :(得分:0)
我假设您希望在字段填充后更改焦点。我建议使用DocumentListener(或任何SWT调用它)来通知字段内容的更改:如果字符数正确,则跳转到下一个字段。