Disable Canvas ContextMenu in GWT

This week I'm working with canvas and I got a problem to hide the context menu from being appeared. I had try several methods such as handling the mouse up event, click event , sink events but all of them are not working.

Finally, I found a solution from 
http://svenbuschbeck.net/wordpress/2011/02/disable-context-menu-in-gwt/

The solution is similar to mouse up event but this one is using DomHandler.

Canvas canvas = Canvas.createIfSupported();
if (canvas == null) {
    return;
}

canvas.addDomHandler(new ContextMenuHandler() {

    @Override
    public void onContextMenu(ContextMenuEvent event) {
        event.preventDefault();
        event.stopPropagation();
    }
},ContextMenuEvent.getType());

0 comments:

 
Copyright © peyotest