Hye there I am searching for how to enable (only and only) right click and show a popup menu in jFrame using NetBeans; using my code as:
private void formMouseClicked(java.awt.event.MouseEvent evt){
pop.show(evt.getComponent(),evt.getX(), evt.getY());
}
I'm still unable to get the best results because it also popups on left click too suggest me any hint that I'm doing any blunders Thanks in advance.
You can use:
if (evt.isPopupTrigger()){
//Show menu and do stuff here
}
This is what it should done like this truly It's amazing and helpful
private void textfiledMousePressed(java.awt.event.MouseEvent evt) {
if (evt.getModifiers() == MouseEvent.BUTTON3_MASK){
p.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
don't forget to add an import for
import java.awt.event.MouseEvent;
have fun...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.