Vaadin中的ENTER快捷键和TextArea

时间:2012-05-30 16:12:27

标签: java vaadin keyboard-shortcuts vaadin7

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

热门使快捷方式仅在from文本字段中起作用?

3 个答案:

答案 0 :(得分:9)

使用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();
        }
    });

答案 1 :(得分:1)

较新版本的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();
        }
    });

答案 2 :(得分:0)

谈论Vaadin 14 我一直在寻找答案,对我来说,这很好用

  Button search = new Button("Search");
  search.addClickShortcut(Key.ENTER);