views:

952

answers:

4

I am writing a Java Application for Data Entry using Eclipse and SWT. Naturally it has a great many Text objects.

What I would like to happen is that when user enters something into one field focus automatically changes to the next field.

Thanks in advance

+2  A: 

public void keyPressed(KeyEvent e) { if (x.getText().length() == 1); { x.traverse(SWT.TRAVERSE_TAB_NEXT); }

  }});
Drazen Urch
+1  A: 
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);
  }
 }});
James Van Huis
A: 

I assume you want to change the focus after the field has been filled. I suggest using a DocumentListener (or whatever SWT calls it) to be notified of changes to the field's content: if it has the right number of characters, jump to the next field.

Alan Moore
+1  A: 

You may also want to have a look at the VerifyListener interface. See this interesting blog post for a caveat though: http://eclipsenuggets.blogspot.com/2008/10/eclipse-bug-patterns-selfish-validation.html

Daniel Schneller