Adding a MouseOverHandler to an Element?

前端 未结 4 2048
悲&欢浪女
悲&欢浪女 2021-02-08 18:14

I would like to listen for the mouse over event in GWT 1.6. Since GWT 1.6 has introduced handlers and deprecated listeners I\'m unsure as to how I can accomplish this with what

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 18:38

    If you know the element's type, you can wrap the Element and get the appropriate Widget back. In the case of, say, an Image:

    Element el = DOM.getElementById("someImageOnThePage");
    Image i = Image.wrap(el);
    i.addMouseOverHandler(...);
    

    The only problem with this I've encountered is you'll get an AssertionError in HostedMode if the element is already attached to another parent widget. It'll work fine in production however. There's probably a good reason for that assertion, so be careful.

提交回复
热议问题