提问者:小点点

Vaadin中的ENTER快捷方式和TextArea


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

热使快捷方式只在从文本字段中工作?


共3个答案

匿名用户

使用焦点和模糊侦听器删除和添加快捷键:

    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);