File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MouseListener / Right Click ?

 
Avin Sinanan
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to write the code for the following:
Lets sat you have the button:
JButton button = new JButton("Right Click me");
How do you write a mouse listener so that when you right click on it the following fucntion is executed :
System.out.println("thanks");
Thanks in advance
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you have to do is add a MouseListener to the component that defines what to do in it's mousePressed method. In that method it should test isMetaDown on the MouseEvent it recieved. The code below illustrates one way to do this...



-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic