简体   繁体   English

Swing:有没有办法检测鼠标是否静止?

[英]Swing: Is there a way to detect if the mouse is still?

在MouseInputAdapter下,有一个mousePressed,mouseReleased,mouseDragged和mouseMoved的侦听器,但是当鼠标静止时是否有一个侦听器?

There is no such event built in. 没有内置此类事件。

If you need that functionality, you may want to consider using a timer. 如果需要该功能,则可能需要考虑使用计时器。 Set the timer to the length of time you want the mouse to be idle before the event is fired. 将计时器设置为您希望鼠标在事件触发之前处于空闲状态的时间长度。 Be sure to reset the timer in the MouseMoved event. 确保在MouseMoved事件中重置计时器。 You probably want to enable and reset the timer on MouseEnter and disable the timer on MouseLeave. 您可能要在MouseEnter上启用和重置计时器,并在MouseLeave上禁用计时器。

No, there's no such listener ie method. 不,没有这样的监听器,即方法。 It's just that, when none of these events is triggered you may assume the mouse is still. 只是,当这些事件均未触发时,您可能会认为鼠标静止不动。

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

相关问题 摆动:检测鼠标在一般路径上的移动 - Swing: detect mouse move on generalpath 如何在Java Swing应用程序中检查鼠标是否仍然被按下 - How to check if mouse pressed and still pressed on a button in java swing app 如何在Java(Swing)中检测3个以上的鼠标按钮? - How to detect more than 3 mouse buttons in Java (Swing)? "java - 如何检测用户正在使用触控板而不是Java swing中的鼠标?" - How to detect the user is using the Trackpad and not the mouse in Java swing? 有没有办法检测在另一个JLabel上释放的鼠标? - Is there a way to detect mouse released on another JLabel? 在Swing中,是否可以从工具箱中提取预定义的鼠标光标图像? - In Swing, is there a way to extract a predefined mouse cursor Image from the toolkit? 有没有办法为Java Swing应用程序设置默认的鼠标光标图像? - Is there a way to set the default mouse cursor image for a java Swing application? 使用带有 Swing 的鼠标绘制(单色)数组的最简单方法是什么? - What's the easiest way to draw a (monochrome) array using a mouse with Swing? Java Swing JFrame突然停止响应鼠标输入,但仍然需要键盘输入 - Java Swing JFrame suddenly stops responding to mouse input, but still takes keyboard inputs 如何使用swing类Java绘制网格并在单击和拖动时检测鼠标位置 - How to draw grid using swing class Java and detect mouse position when click and drag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM