wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Frame.getLocation() slow to update - need realtime position Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frame.getLocation() slow to update - need realtime position" Watch "Frame.getLocation() slow to update - need realtime position" New topic
Author

Frame.getLocation() slow to update - need realtime position

Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I have a component that I want to move when someone moves a parent AWT frame. I want the component to seemlessly follow the frame, as if they were one. However, getting the location of the frame is not seemless, it's jerky. Adding a ComponentListener with a componentMoved also has this same jerky I moved, second later, I moved again. I want the position of the Frame to be updated every frame, instead of when I stop moving, so that I get the positions in between and can setLocation() on the other component.

Any way to get the accurate location through the entire move process so I don't get this jerky effect?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

I don't get that problem with the following example code:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I get the issue with your code as well. The frames don't move in realtime together. If I grab the frame and wildly move it around the screen, the second frame doesn't move into position until I stop moving the first frame. I need both frames to move as one.

Mac OS X 10.7
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
I get the issue with your code as well.


Rob's code works fine for me. I'm using JDK6_7 on XP.

If you have a problem then its probably a version or platform problem.

I'm guessing a platform problem. Maybe the componentMoved() event doesn't fire until the mouse is released?
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

It's not on mouse release. It's when the frame stops moving. I can still have the mouse held, drag it some more. Each time I stop, the other frame will jump to position. If I spin the frame in circles, the second frame just sits there, until I stop, then jumps to position. Weird
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
So why didn't you post you JDK version and platform???

Maybe someone else who has the same setup will test your code to see if they have the same problem or can provide a solution.

Edit:

Must be going blind, I missed the platform comment.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I stated above that I'm running Mac OSX 10.7 (Lion). It has the latest JRE for that OS, which is 1.6.0_26.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I tested it on Windows 7 running 1.6.0_26 and had no issues, so thus far, it's a problem on the Mac.
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

Seems I'm not the only one, but I haven't seen a fix, though some suggested trying to capture mouseDragged. Guess it's been an issue on the Mac for a while, seems to be reported as "regression bug, 7731968", though I can't check it.

http://markmail.org/message/mxcextifjdn4xuq3
http://lists.apple.com/archives/java-dev/2003/Mar/msg01484.html
http://stackoverflow.com/questions/757078/events-for-window-dragging-in-java
http://stackoverflow.com/questions/3035054/getting-a-jframes-actual-current-location
 
jQuery in Action, 2nd edition
 
subject: Frame.getLocation() slow to update - need realtime position
 
Similar Threads
fix JDialog position relative to its parent JFrame component
setEditable and blinking cursor
CTRL+TAB in Jcomponent
How add comp to frame so x,y pos and height never changes, width does adjust?
How to build focus rectangle