TextField f = new TextField();
Button b = new Button("Save");
b.setClickShortcut(KeyCode.ENTER); // For quick saving from text field itself
TextArea longText = new TextArea(); // "Enter" is garbled here
使快捷方式仅在来自文本字段中有效吗?
TextField f = new TextField();
Button b = new Button("Save");
b.setClickShortcut(KeyCode.ENTER); // For quick saving from text field itself
TextArea longText = new TextArea(); // "Enter" is garbled here
使快捷方式仅在来自文本字段中有效吗?
使用 focus 和 blur listeners 移除和添加快捷键:
f.addFocusListener(new FocusListener() {
@Override
public void focus(FocusEvent event) {
b.setClickShortcut(KeyCode.ENTER);
}
});
f.addBlurListener(new BlurListener() {
@Override
public void blur(BlurEvent event) {
b.removeClickShortcut();
}
});
较新版本的 Vaadin 需要以下代码,因为 addListener() 现在已弃用。
f.addFocusListener(new FocusListener() {
private static final long serialVersionUID = -6733373447805994139L;
@Override
public void focus(FocusEvent event) {
b.setClickShortcut(KeyCode.ENTER);
}
});
f.addBlurListener(new BlurListener() {
private static final long serialVersionUID = -3673311830300629513L;
@Override
public void blur(BlurEvent event) {
b.removeClickShortcut();
}
});
谈到 Vaadin 14,我一直在寻找答案,对我来说,这很好用
Button search = new Button("Search");
search.addClickShortcut(Key.ENTER);