Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top