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
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.