在jFrame中启用右键单击 [英] Enable right click in jFrame

查看:124
本文介绍了在jFrame中启用右键单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hye我正在寻找如何启用(只有和唯一)右键单击并使用NetBeans在jFrame中显示一个弹出菜单;使用我的代码为:

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.

推荐答案

这应该这样做真正的惊人和有用的

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;

有乐趣...

这篇关于在jFrame中启用右键单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆