简体   繁体   English

JmenuItem按下鼠标可工作,但单击鼠标事件不起作用? 为什么?

[英]JmenuItem mouse pressed work but mouse clicked event does not work? why?

I was trying to create a mouse clicked event of a JmenuItem but it did not work but mouse pressed event works. 我试图创建JmenuItem的鼠标单击事件,但是它不起作用,但是鼠标单击事件有效。 what is the difference between clicked and pressed and why only pressed works here? 单击和按下之间有什么区别?为什么只有按下在这里起作用?

Works fine for me. 对我来说很好。 A mouseClicked is generated when a mousePressed and mouseReleased is received at the same pixel location. 当在同一像素位置接收到mousePressed和mouseReleased时,将生成mouseClicked。 If you move the mouse even 1 pixel between the two events the mouseClicked is not generated. 如果在两个事件之间将鼠标移动甚至1个像素,则不会生成mouseClicked。

That is why you should stick with the ActionListener which is the way a menu item was designed to be used. 因此,您应该坚持使用ActionListener,这是设计菜单项使用方式的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM