在我的三个按钮鼠标 MouseEvent.BUTTON2 = 中键点击和 MouseEvent.BUTTON3 = 右键点击。
MouseEvent.BUTTON2
MouseEvent.BUTTON3
这是双按钮鼠标的情况吗?
谢谢
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.
BUTTON3
To avoid any ambiguity, use the utilities methods from 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)
I've seen
anEvent.isPopupTrigger()
be used before. I'm fairly new to Java so I'm happy to hear thoughts about this approach :)