我正在尋找一種方法來在VerticalLayout或其他方式中使用回車鍵傳遞字段。在vaadin書中有一個Shortcut和Handler監聽器的例子,但我不知道如何實現它。使用回車鍵傳遞字段?
我正在試着這個。
public class MyWindow extends Window implements Handler{
private Action action_enter; //pass fields with enter
private Action action_esc;
private TextField name, lastName;
public MyWindow(){
super("this window is opened");
VerticalLayout vLayout = new VerticalLayout();
setContent(vLayout);
center();
setModal(true);
setClosable(false);
setDraggable(false);
setResizable(false);
//actions
action_enter = new ShortcutAction("Enter key", ShortcutAction.KeyCode.ENTER, null);
action_esc = new ShortcutAction("Esc key", ShortcutAction.KeyCode.ESCAPE, null);
addActionHandler(this);
//fields
name = new TextField("Name");
lastName = new TextField("Last name");
name.focus();
vLayout.addComponent(name);
vLayout.addComponent(lastName);
}
@Override
public Action[] getActions(Object target, Object sender) {
return new Action[] { action_enter, action_esc };
}
@Override
public void handleAction(Action action, Object sender, Object target) {
/** close window with esc key */
if(action == action_esc){
close();
}
/** pass fields with enter key */
if(action == action_enter){
//here pass fields with enter key
}
}
}
什麼想法?
如何使用,而不是輸入選項卡更改文本字段的重點是什麼? – FernandoPaiva