• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

problem with moving a JWindow

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic