Disable Context Menu in GWT

To make use of the right mouse but­ton, it is nec­es­sary to dis­able the native browser con­text menu (the pop­up menu appear­ing on right click). This can be achieved like this:

RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() {

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

Same should work for RootPanel.

After that, it is pos­si­ble to make use of the right mouse but­ton for exam­ple like this:

someWidget.addDomHandler(new MouseMoveHandler() {

	@Override public void onMouseMove(MouseMoveEvent event) {
		if (event.getNativeButton() == NativeEvent.BUTTON_RIGHT) {
		...

One Reply to “Disable Context Menu in GWT

Leave a Reply

Your email address will not be published. Required fields are marked *