停止在GWT冒泡的事件 [英] Stop a event from bubbling in GWT

查看:98
本文介绍了停止在GWT冒泡的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
public void onKeyPress(Widget sender,char keyCode,int modifier){
// do something
//我希望停止从这个关键字发起的事件从BUBBING进一步
}
}

如何停止导致此方法被调用的事件从changeTextArea冒泡到面板/小部件/复合材料/无论包含changeTextArea。简单地说,我如何阻止它进一步冒泡,任何帮助将不胜感激(特别是代码示例)。

解决方案

据我所知,您无法通过键盘监听器进行操作,但可以通过使用DOM类添加事件预览:

  DOM.addEventPreview(EventPreview preview)

然后当你获取事件:

  onEventPreview(事件事件)

你应该返回false,说你想取消事件。 Event对象还支持这种方法:

  public final void cancelBubble(boolean cancel)

取消给定事件的冒泡。这将阻止事件传播到父元素。



您可以在这里找到更多详细信息:
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.html?overview-summary.html


I have the following snippet of code, changeTextArea is a TextArea object.

changeTextArea.addKeyboardListener(new KeyboardListenerAdapter()
  public void onKeyPress( Widget sender, char keyCode, int modifier){
    //do something
    //I WISH TO STOP THE EVENT THAT MAPS TO THIS KEYPRESS FROM BUBBLING ANY FURTHER
  }
}

How would I stop the Event that is causing this method to be called from bubbling up from changeTextArea into the Panels/Widgets/Composites/Whatever that contain changeTextArea. Put succinctly, how do I stop it from bubbling any further. Any help would be appreciated (especially code samples).

解决方案

As far as I know you can't do it via a keyboard listener, but it is possible by adding an event preview using the DOM class:

DOM.addEventPreview(EventPreview preview) 

Then when you get the event:

onEventPreview(Event event) 

You should return false, to say you want to cancel the event. The Event object also supports this method:

public final void cancelBubble(boolean cancel)

Cancels bubbling for the given event. This will stop the event from being propagated to parent elements.

You can find more details here: http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.html?overview-summary.html

这篇关于停止在GWT冒泡的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆