ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Java Swing: Menus and Toolbars, Part 4
Subject:   right mouse button events
Date:   2003-03-07 05:23:28
From:   zeevlazarev
In Java the right mouse button events implemented as some kind of "secondary importance" events and they even not included in the MouseListener interface. Instead, you should check for isPopupTrigger() of MouseEvent to catch right mouse button events.
And it really works fine for popup menus.
The problem is that when you press on right mouse button you have got both events - the first activated event is the mousePressed and the second one is the popupTrigger == true.
How can I handle this problem - eliminate mousePressed event when I want only popupTrigger event?
In my code I also use the same approach:
processMouseEvent(MouseEvent e)
{
if e.isPopupTrigger()
rightMousePressed(e) // this is my function
else
super.processMouseEvent(e)
}