Sor*_*son 8 ajax gwt right-click
我正在使用GWT构建一个AJAX Web应用程序,我想使用右键单击各种内容,就像在桌面应用程序中一样.但是,右键单击会生成标准Web上下文菜单,并且永远不会调用void onClick(ClickEvent事件).有没有人想出如何让这个工作?谢谢!
容易腻,在contextmenuhandler上添加一个监听器,它将根据用户右键单击的位置显示一个小部件.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();
}
}
Run Code Online (Sandbox Code Playgroud)
最后,您将要禁用浏览器菜单以完全重载此类上下文菜单.除了opera之外,这应该适用于所有浏览器.但老实说,谁现在使用那些新的^ _______ ^
<body oncontextmenu="return false;">
Run Code Online (Sandbox Code Playgroud)
事实证明你可以通过扩展来做到这一点DeckPanel。这里有一个精彩的讨论,还有一个证明它有效的演示。
http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/
| 归档时间: |
|
| 查看次数: |
7505 次 |
| 最近记录: |