Java中的窗口拖动事件 [英] Events For Window Dragging in Java

查看:278
本文介绍了Java中的窗口拖动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Java中实现类似于OS X抽屉的功能,因此我将一个窗口隐藏在另一个窗口之下.但是,当我拖动主窗口(JFrame)时,我需要在其移至下面的辅助窗口(JWindow)时发送更新.

I'm trying to implement an OS X drawer like feature in Java, and so I'm going to have one window hiding under another. However when I drag the primary window (JFrame) I need to send updates as it moves to the secondary window (JWindow) below.

所以会是这样的……

---------------
|             |----------
|   JFrame    |          |
|             |  JWidow  |
|             |          |
|             |          |
|             |          |
|             |-----------
---------------

也就是说,OS X中的ComponentListener不会发送componentMoved的持续更新,仅当您暂停一秒钟或提起鼠标时才发送.这似乎与Win/Linux不同,所以我想知道是否有人有不同的解决方案.

That said, ComponentListener in OS X doesn't send constant updates for componentMoved, only when you pause for a second or lift off the mouse. This seems to differ from Win/Linux, so I was wondering if anyone had a different solution.

在没有完全理解所有内容的情况下,我希望获取并处理绘制窗口标题栏的所有内容(似乎与根窗格有关).我什至不确定这是否可行,但这是我可以想到的唯一其他解决方案,它可以确定何时拖动整个窗口.

Without completely understanding everything, I was hoping to get and deal with whatever is drawing the window's titlebar (something about the rootpane it seems). I'm not even sure if that is going to be possible to do, but it is the only other solution I can think of to determine when the whole window is being dragged.

感谢您的帮助!

推荐答案

是否可以使用mouseMotionListener来查看鼠标是否在移动,如果可以移动,请使用getLocation()更新第二个窗口的位置.您还可以检查当前位置是否等于先前位置,以防止浪费资源.我不确定getLocation()是否会正常运行,但这确实取决于操作系统如何处理.

Could you use a mouseMotionListener to see if the mouse is moving, and if it is, update the position of the second window using getLocation(). You can also check that the current position is equal to the previous position to prevent wasting resources. I'm not sure if getLocation() will work properly though, it really does depend on how the Operating System handles it.

这篇关于Java中的窗口拖动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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