Java 鼠标右键单击事件
在我的三键鼠标上 MouseEvent.BUTTON2
= 中键单击和 MouseEvent.BUTTON3
= 右键单击。
两键鼠标上是否存在这种情况?
谢谢
On my three button mouse MouseEvent.BUTTON2
= Middle Click and MouseEvent.BUTTON3
= Right Click.
Is this the case on a two button mouse?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了避免任何歧义,请使用 SwingUtilities :
SwingUtilities.isLeftMouseButton(MouseEvent anEvent)
SwingUtilities.isRightMouseButton(MouseEvent anEvent)
SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)
To avoid any ambiguity, use the utilities methods from SwingUtilities :
SwingUtilities.isLeftMouseButton(MouseEvent anEvent)
SwingUtilities.isRightMouseButton(MouseEvent anEvent)
SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)
是的,看看这个讨论平台之间差异的帖子。
如何检测 Mac 操作系统的右键单击事件
BUTTON3
在所有平台上都是相同的,相当于鼠标右键。如果中间按钮不存在,则 BUTTON2 将被忽略。Yes, take a look at this thread which talks about the differences between platforms.
How to detect right-click event for Mac OS
BUTTON3
is the same across all platforms, being equal to the right mouse button. BUTTON2 is simply ignored if the middle button does not exist.我以前见过
用过。我对 Java 还很陌生,所以我很高兴听到关于这种方法的想法:)
I've seen
be used before. I'm fairly new to Java so I'm happy to hear thoughts about this approach :)