Mouse Over listener for FlexTable in GWT 1.7?

帅比萌擦擦* 提交于 2019-12-22 14:08:38

问题


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 in CSS) how do I add a Hover listener to a FlexTable for example?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/1809155/mouse-over-listener-for-flextable-in-gwt-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!