如何使用JavaEE Vaadin Framework TextField1输入下一步移动到游标TextField2?

时间:2015-09-19 12:33:44

标签: vaadin textfield enter

如何不接受任何输入----> Sicil no ENTER ----> TC Kimlik没有进入BORÇ_BUL?

enter image description here

1 个答案:

答案 0 :(得分:0)

如果你想使用ENTER键作为TAB键。下面的代码不是很优雅,但它的工作原理。你可以重构,从数组中设置顺序等等......

想象一下登录表单(用户和密码字段和登录按钮):

public class LoginView extends VerticalLayout {

private TextField username;
private PasswordField passwordFld;
private AbstractTextField current;

public LoginView(
    buildFields();
}

private void buildFields(){
    HorizontalLayout fields = new HorizontalLayout();
    username = new TextField("User");
    passwordFld = new PasswordField("Pwd");
    Button signin = new Button("Sign");
    fields.addComponents(username, passwordFld,signin);         

    username.addFocusListener(new FocusListener() {     
        public void focus(FocusEvent event) {
            current = username;             
        }
    });
    passwordFld.addFocusListener(new FocusListener() {      
        public void focus(FocusEvent event) {
            current = passwordFld;              
        }
    });
    ShortcutListener enterkey = new ShortcutListener ("Enter",  KeyCode.ENTER, null){
        public void handleAction(Object sender, Object target) {
            if (current.equals(username)){
                passwordFld.focus();
            }else if (current.equals(passwordFld)){
                sign();
            }else{
                sign();
            }
        }       
    };
    fields.addShortcutListener(enterkey );      
    signin.addClickListener(getClickListener());        
    addComponent(fields);
}

private ClickListener getClickListener() {
    return new ClickListener() {            
        public void buttonClick(final ClickEvent event) {
            sign();
        }
    };
}
private void sign(){
//Do the sign in or fail
    }
   }