Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将实现视图移动,我只需要知道鼠标是否在屏幕外(窗口外)并相应地调整偏移变量。
也许您可以使用 MouseListener 来监听 mouseExited 事件。然后您可以使用 MouseInfo 类来获取鼠标的当前位置,然后相应地重置窗口的位置。
如果鼠标移动得太快,重置位置后鼠标可能仍然在窗口之外,因此您可能需要启动 Timer 不断检查 MouseInfo 以获取当前鼠标位置,然后不断调整窗口位置。如果在任何时候生成了 mouseEntered 事件,那么您可以停止 Timer。