开发者

Mouse Over listener for FlexTable in GWT 1.7?

How do you add an event listener or handler to widgets in GWT 1.7?

I know there are some questions alreayd about this on SO but it seems they are outdated. For example (ignoring the fact that there is a :hover开发者_JAVA技巧 in CSS) how do I add a Hover listener to a FlexTable for example?


If you want to add a MouseOverHandler to a FlexTable try this:

public class MyFlexTable extends FlexTable implements MouseOverHandler, HasMouseOverHandler {
    public MyFlexTable() {
        this.addMouseOverHandler(this);
    }

    public void onMouseOver(MouseOverEvent event) {
        //do something
    }
    public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
        return addDomHandler(handler, MouseOverEvent.getType());
    }
}


Starting in GWT 1.6 you use Handlers instead of Listeners. So for example, for hovering you would add a MouseOverHandler and MouseOutHandler. The FlexTable itself doesn't implement these interfaces so you'll probably want to implement it on the widgets contained in the FlexTable. For example,

myWidget.addMouseOverHandler(new MouseOverHandler(){
   void onMouseOver(MouseOverEvent event){
       doHovering();
    }
});

Similarly for adding a MouseOutHandler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜