【发布时间】:2014-02-18 16:53:22
【问题描述】:
我正在寻找一种在 VerticalLayout 或其他中使用 enter 键传递字段的方法。在 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
}
}
}
有什么想法吗?
【问题讨论】:
-
如何使用 Enter 代替 Tab 更改 TextField 的焦点?
标签: java frameworks vaadin vaadin7