0

I have been working on how to enable the right click and show a popup menu it was asked earlier at Enable right click in jFrame but it was not as useful actually my problem is that I am facing the left click as enable also my piece of code that I have been using is:

     private void jTextField1MousePressed(java.awt.event.MouseEvent evt){
        if (!evt.isPopupTrigger()){
           p.show(evt.getComponent(), evt.getX(), evt.getY());
        }
     }

The problem is that the left mouse click is also popping up a menu. What I want is to just pop up the menu on the right click. Please suggest me a solution and the blunder I'm doing here Thanks in advance

Community
  • 1
  • 1
Tech Nerd
  • 822
  • 1
  • 13
  • 39
  • 1
    Why don't you continue with your previous question ? Why did you accept an answer if it does not solve your problem ? – Apurv Apr 26 '13 at 11:59
  • how can i continue with my previous attempt please let me know I'm sorry for this now topic @Apurv and Andrew Thompson – Tech Nerd Apr 26 '13 at 12:01
  • @user2277645 `The problem is that the left mouse click is also popping up a menu.` I can't believe, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, just about JFrame with JTextField and your definition for (empty)JPopupMenu – mKorbel Apr 26 '13 at 12:15
  • @mKorbel below is the solution mentioned for my problem thanks for your kind reply sir – Tech Nerd Apr 26 '13 at 12:20
  • @user2277645 I think that not (reason for my comment:-), this isn't about how the JPopup works :-) – mKorbel Apr 26 '13 at 12:30

1 Answers1

4

I think this code snippet will help you:

if (evt.getModifiers() == MouseEvent.BUTTON3_MASK){  
    //right click  
}

For further information see the JDoc of MouseEvent.

Eich
  • 3,728
  • 1
  • 21
  • 34