Question

Ok, for label, we got ClickHandler, ie, when we click on the label it will do something.

But I want to do something like Right-ClickHandler for Label, ie, when user right click on the label, it will do something.

Some people say put the widget into DeckPanel & do the RightClick Hanler on it. But if we have a lot of labels, then

does each label have to be put into a deck panel?

If that is the case then the code maybe complicated, so I want to do the RightClick handler for label just like i do normal ClickHandler. How to do do?

Was it helpful?

Solution

I am heavily recommending this example (Which is bit old but the right way to deal with context menu).

   lable.sinkEvents(Event.ONCONTEXTMENU);
    lable.addHandler(
      new ContextMenuHandler() {
        @Override
        public void onContextMenu(ContextMenuEvent event) {
          event.preventDefault();
          event.stopPropagation();
          popupMenu.setPopupPosition(              //custom menu here
            event.getNativeEvent().getClientX(),
            event.getNativeEvent().getClientY());
          popupMenu.show();
    }
    }, ContextMenuEvent.getType())

Continue reading ....

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