Friday, July 30, 2010

why doesn't this right-click capture work in IE?

I'm trying to capture right-clicks on a widget, to popup my own
context menu instead of the browser's. I've researched it a bit and
pieced together bits and I've got it working in Chrome and FF but not
IE. In IE it doesn't display the default browser context menu, but it
doesn't display my popup menu either. I'm just getting into GWT so I'm
assuming I'm not doing something right with the right kinds of
handlers or events. I'm also using the gwt-graphics module, that's
where the Rectangle class that I'm extending comes from, in case
that's relevant.

Here's my code:

public class RectangleRightClickable extends Rectangle {

public RectangleRightClickable(int x, int y, int width, int height) {
super(x, y, width, height);

public void onBrowserEvent(Event event) {
GWT.log("event type : " + DOM.eventGetType(event));
switch(DOM.eventGetType(event)) {
if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT) {
GWT.log("Event.BUTTON_RIGHT", null);

protected void showMenu() {
final RectangleRightClickable parent = this;
final PopupMenu popMenu = new PopupMenu();
popMenu.addMenuItem(new Label("Add thing"));
popMenu.setPopupPositionAndShow(new PopupPanel.PositionCallback()
public void setPosition(int offsetWidth, int offsetHeight) {
int left = parent.getX() + parent.getWidth();
int top = parent.getY() + parent.getWidth();
popMenu.setPopupPosition(left, top);


You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment