本文介绍了右键单击GWT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个AJAX的web应用程序使用GWT,我想用右键点击各种事情,就像在一个桌面应用程序。但是,右键单击生产标准的Web上下文菜单,无效的onClick(ClickEvent事件)不会被调用。有没有人想出如何得到这个工作?谢谢!

I am building an AJAX web app with GWT, and I want to use right-click for various things, just like in a desktop app. However, right-click produces the standard Web context menu and void onClick(ClickEvent event) never gets called. Has anyone figured out how to get this to work? thanks!

推荐答案

易peasy,在其将基于这样的用户右键单击显示插件的contextmenuhandler添加监听器。 https://confluence.clazzes.org/pages/viewpage.action?pageId=425996

easy peasy, add a listener on the contextmenuhandler which will display a widget based on where the user right clicks. https://confluence.clazzes.org/pages/viewpage.action?pageId=425996

class MyWidget extends Composite implements ContextMenuHandler {

  // just an example, use a meaningful Widget here...
  private Widget base;

  private PopupPanel contextMenu;


  public MyWidget() {
    // initialize base widget, etc...

    this.contextMenu = new PopupPanel(true);
    this.contextMenu.add(new HTML("My Context menu!"));
    this.contextMenu.hide();

    initWidget(this.base);

    // of course it would be better if base would implement HasContextMenuHandlers, but the effect is the same
    addDomHandler(this, ContextMenuEvent.getType());
  }


  public void onContextMenu(ContextMenuEvent event) {
    // stop the browser from opening the context menu
    event.preventDefault();
    event.stopPropagation();


    this.contextMenu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
    this.contextMenu.show();
  }

}

最后,你会想禁用浏览器菜单中这种类型的上下文菜单的全超载。这应该适用于所有的浏览器除歌剧。但老实说,谁使用,这些天NEWAYS ^ _______ ^

<body oncontextmenu="return false;">

这篇关于右键单击GWT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 15:55