File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Rightclicking on components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rightclicking on components" Watch "Rightclicking on components" New topic

Rightclicking on components

Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
I have made a class that extend a JButton, now I would like to show a popup when I make a rightclick over the component!
The same procedure works perfect with JLabel!
Why does it not work with JButton?
/Emil Karlsson
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
some code of yours would be helpful. especially, where you catch the popup events for your JLabel and for your JButton.
are you checking whether the mouse event is a popup trigger? (event.isPopupTrigger())
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I don't know how to do it with your extended button, since you didn't post the code... but here's how you can add a popup menu to a normal JButton...

( Chantal - for some weird reason isPopupTrigger() wouldn't work... I had to use isMetaDown()... )

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
Thanks a lot.
Now it works as I want.
I agree. Here's the link:
subject: Rightclicking on components
It's not a secret anymore!