File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Dragging a JWindow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dragging a JWindow" Watch "Dragging a JWindow" New topic

Dragging a JWindow

Buckley Lee

Joined: Mar 28, 2001
Posts: 19
I have written some code to make a JWindow draggable by using mouse and mouse motion listeners and redrawing the window as the user drags it with the mouse. However, I'm running into some problems that I would like help on.
The problem seems to occur at random time intervals, but occurs with greater probability when the mouse is moved very rapidly while dragging the window. The window is redrawn just fine, but every now and then it has a sparodic behavior in how it gets drawn to the screen. It will re-draw on one part of the window, hide itself, then re-draw on another part of the window (NOT where the mouse cursor is dragging it), hide itself, re-draw on yet another part of the window (again, NOT where the mouse cursor is dragging it), etc, etc. It will do this for about a 1/2 second to one second before following the mouse cursor again.
Does anyone have any experience dragging JWindows? If so, I could use your help. Thanks!!
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
Sounds like a problem that could be solved with double-buffering...this involves painting the new image to a storage area of memory before it is actually painted to the screen. The result is flicker-free animation, or in your case, hopefully smooth error-free repainting of the window. Do a search for double-buffering in the popular applet tutorials, and I'm sure you'll find out more details of how to implement the technique.
  • Ryan Burgdorfer
  • Java Acolyte in
  • Columbus, OH USA

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Buckley Lee

Joined: Mar 28, 2001
Posts: 19
No, I've tried double bufferring and that didn't seem to work. The window still had a little sparodic behavior in WHERE it gets re-drawn in relation to the mouse. I'm wondering if the window re-draws just can't keep up with the mouse events and thats the reason for the strange behavior?
Instead of dragging the JWindow, I'm now displaying a JFrame on top of the JWindow as the user begins to drag the JWindow. Currently I'm using the JWindow mouse events to control the movement of the JFrame, then upon release of the mouse button the JWindow is re-drawn on top of the JFrame. The JFrame DOES NOT have the sparodic re-draw behavior like the JWindow (when it gets dragged with mouse events), * BUT *, is it possible to hand off the mouse event to the JFrame so that the movement of the JFrame does not have to be controlled by the JWindow mouse events? Only ONE button press of the mouse is desired here.
I am wanting to use a JWindow in my application because the title bar on the JFrame/Frame is taking up too much desktop space.
Once again, thanks for any ideas.
I agree. Here's the link:
subject: Dragging a JWindow
It's not a secret anymore!