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...
来源:https://stackoverflow.com/questions/16198383/enable-right-click-in-jframe