在 GWT 中右键单击?
我正在使用 GWT 构建一个 AJAX Web 应用程序,并且我想使用右键单击来执行各种操作,就像在桌面应用程序中一样。然而,右键单击会生成标准的 Web 上下文菜单,并且 void onClick(ClickEvent event) 永远不会被调用。有谁知道如何让它发挥作用吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很简单,在 contextmenuhandler 上添加一个侦听器,它将根据用户右键单击的位置显示一个小部件。 https://confluence.clazzes.org/pages/viewpage.action?pageId=425996
最后,您需要禁用浏览器菜单以完全重载此类上下文菜单。这应该适用于除 Opera 之外的所有浏览器。但老实说,现在谁用它了^_______^
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
lastly you will want to disable the browsers menu for full overloading of this type of context menu. That should work in all of the browsers except opera. but honestly who uses that these days neways ^_______^
事实证明,您可以通过扩展
DeckPanel
来做到这一点。这里有一个精彩的讨论,还有一个证明它有效的演示。http://whatwouldnickdo.com/wordpress/370/gwt-right -单击上下文菜单/
It turns out you can do it by extending
DeckPanel
. Here's an excellent discussion, along with a nice demo that proves it works.http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/
尽管有多种方法可以做到这一点,但我相信 GWT 团队对此进行了辩论,并认为在 Web 应用程序中启用右键单击是一件坏事,因此有意识地决定不支持它。争论的焦点是,右键单击应该继续按预期工作(调出主机浏览器的右键单击上下文菜单),并且覆盖此行为会破坏预期行为,并且这将是不好的做法。虽然我曾经遇到过右键单击上下文菜单通常很有用的情况,但我倾向于同意 GWT 团队的决定。
Although there are ways of doing it I believe the GWT team had a debate about this and decided enabling right click in a web app was a bad thing and so made the concious decision not to support it. The argument was that right click should continue to work as expected (bring up the host browser's right click context menu) and overriding this was breaking that expected behaviour and that and would be bad practice. While I have had instances where a right click context menu would be useful generally I tend to agree with the GWT team's decision.