This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jeff Gent
Ranch Hand
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get that problem with the following example code:
 
Jeff Gent
Ranch Hand
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2582
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2582
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic