How to detect right-click event for Mac OS

后端 未结 4 1524
野的像风
野的像风 2020-12-18 05:10

For windows and linux I am able to detect right click. But for mac I donot know how to detect right-click.

How to write java program to detect right click for Mac OS

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 06:03

    Instead of using MouseEvent.BUTTON3, a bettter self docummenting approach is to use

    if (SwingUtilities.isRightMouseButton(event))
       // do something
    

    Also, if you are using this code to display a popup menu, then you should not be using this approach since each OS has different key strokes to inovoke the popup menu. Read the section from the Swing tutorial on Bringing Up a Popup Menu.

提交回复
热议问题