Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with moving a JWindow

 
kalle svensson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder how to get a JWindow to move across the screen in location after the user's mouse pointer.
When i use the method setLocation((MouseEvent).getX(), (MouseEvent).getY()) in an mousemotion adapter attched to the JWindow a
lot of flicker occurs on the screen. In the code above a JWindow appears and when the user clicks on the yes button then the text "good luck"
displays before the window is closed after a small delay.

The code below is written just for this post. How can i move the window without generating the flicker, what is the general solution for this problem?
I will be very much greatful for any help on this subject.
// kalle

 
Rob Camick
Ranch Hand
Posts: 2564
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main problem is that the MouseEvents are relative to the component and so the location never changes by more than a pixel, so you keep set the window location back to where it was even as the mouse is continually moving acros the screen.

Generally, moving a component is handled by dragging the component which mean using the mouseDragged() event. A general solution can be found in Moving Windows. This solution converts the mouse events to make the location relative to the screen.

For an older solution that doesn't convert mouse points to the screen, you need to keep track of the previous mouse event so you can determine the change in location:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic