tags:

views:

342

answers:

2

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.

So it'd be something like this…

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

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.

Any help is appreciated!

+1  A: 

Assuming you have trusted code, you can use MouseInfo.getPointerInfo() to get the location of the pointer. This information can be polled so that you can work out where the window should be. You might just be able to poll where the window is anyway.

Tom Hawtin - tackline
I'm not sure how this would be helpful. Fhe cursor position doesn't seem to help with knowing when the main JFrame is being moved does it?I was hoping it is possible to know when mouseDown is fired on the titlebar and then update jwindow pos. for each mouseDragged thereafter.
dustins
Tom Hawtin - tackline
+1  A: 

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.