简体   繁体   English

Java鼠标事件右键单击

[英]Java Mouse Event Right Click

On my three button mouse MouseEvent.BUTTON2 = Middle Click and MouseEvent.BUTTON3 = Right Click. 在我的三键鼠标MouseEvent.BUTTON2 =中键单击和鼠标事件MouseEvent.BUTTON3 =右键单击。

Is this the case on a two button mouse? 这是两键鼠标的情况吗?

Thanks 谢谢

To avoid any ambiguity, use the utilities methods from SwingUtilities : 为避免任何歧义,请使用SwingUtilities中的实用程序方法:

SwingUtilities.isLeftMouseButton(MouseEvent anEvent) SwingUtilities.isRightMouseButton(MouseEvent anEvent) SwingUtilities.isMiddleMouseButton(MouseEvent anEvent) SwingUtilities.isLeftMouseButton(MouseEvent anEvent) SwingUtilities.isRightMouseButton(MouseEvent anEvent) SwingUtilities.isMiddleMouseButton(MouseEvent anEvent)

Yes, take a look at this thread which talks about the differences between platforms. 是的,看看这个讨论平台之间差异的线程。

How to detect right-click event for Mac OS 如何检测Mac OS的右键单击事件

BUTTON3 is the same across all platforms, being equal to the right mouse button. BUTTON3在所有平台上都是相同的,等于鼠标右键。 BUTTON2 is simply ignored if the middle button does not exist. 如果中间按钮不存在,则忽略BUTTON2。

I've seen 我见过

anEvent.isPopupTrigger() 

be used before. 以前用过。 I'm fairly new to Java so I'm happy to hear thoughts about this approach :) 我是Java的新手,所以我很高兴听到有关这种方法的想法:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM