简体   繁体   English

按Enter键后,Eclipse向导关闭

[英]Eclipse wizard closes after pressing Enter key

I've created an Eclipse wizard. 我创建了一个Eclipse向导。 It all works fine except that the wizard closes if I hit the Enter key. 一切正常,但是如果我按Enter键,向导会关闭。

I tried to handle that with a TraverseListener , but it didn't work. 我试图用TraverseListener来解决这个问题,但是没有用。

I also tried SWT.TRAVERSE_RETURN , but it didn't work. 我也尝试了SWT.TRAVERSE_RETURN ,但是没有用。

new TraverseListener() {
            @Override
            public void keyTraversed(TraverseEvent event) {
                if(event.keyCode == SWT.CR){
  /** DO ANYTHING */

                    event.doit = false;
                }
            }
        };

The plugin is written in Java 1.7 in Eclipse Mars. 该插件是用Eclipse Mars中的Java 1.7编写的。

What is the best practice to handle issues like this? 处理此类问题的最佳实践是什么?

Add the traverse listener to the dialog shell and use SWT.TRAVERSE_RETURN 将遍历侦听器添加到对话框外壳并使用SWT.TRAVERSE_RETURN

getShell().addTraverseListener(new TraverseListener() {
   @Override
   public void keyTraversed(TraverseEvent event) {
     if (event.detail == SWT.TRAVERSE_RETURN) {
        event.doit = false;
     }
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM