Reputation: 61041
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?
Upvotes: 2
Views: 2415
Reputation: 5279
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());
}
}
Upvotes: 1
Reputation: 1486
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.
Upvotes: 0