Wednesday, August 30, 2006

Swing Drag Images, Improved

Performance is improved, generating the drag image once instead of repeatedly.




Source

4 comments:

Anonymous said...

I'm trying to test this code but when I try to compile there are 2 classes that cannot be found (1) DragHandler, and (2) ComponentTestFixture.

Any help where to find these classes would be appreciated. They are not included in the source code zip file you provided.

Thank You

technomage said...

ComponentTestFixture is part of the abbot UI test library, available at http://abbot.sf.net but only required for the code's unit tests. You can substitute 0.5f for the missing DragHandler constant.

Anonymous said...

I tried the techniques demonstrated here on one of my own apps. However, as soon as the drag image enters a component it can be dropped into, the cursor flickers like crazy, whcih for some reason, doesn't happen with Sun's BasicDnD demo. Is there anything that can be done about that?
Besides that I'm extremely happy with the solution presented (I tried to implement dragimages myself on windows, and was so disgusted by the result that I gave up).

thx a bunch,
H.

technomage said...

One of the causes of cursor flicker is when there are two sources trying to set the cursor (even if they're setting it to the same thing).

You can avoid the flicker if you have the drag handler's simply not set the cursor.

One other cause is if the cursor in the drag image window doesn't match the cursor in the component below.

You might also try making the drag "aperture" a little larger to avoid the cursor toggling between the drag image and the component below.