Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OutOfMemoryException During Drag and Drop From a Tree



On Wednesday, November 27, 2002, at 03:28 pm, Shankman, Gordon L. wrote:

I am running into a problem when trying to do drag and drop from a large JTree (about 3000 leaves). The default behavior under Mac OS X 10.2 seems to be to create a translucent image of the entire tree during the drag operation and display that image during the drag. I have the JTree displayed in a JScrollPane but the created image is the entire tree, not just the visible portion. The creation of this image causes an OutOfMemoryException that prevents the drag operation from beginning. Is there a non-Mac specific way to stop this image from being created or to force it to only display the visible portion of the tree? I have to be able to compile and run the code on other systems as well (Linux and Windows) so I can't do anything specific to OS X.

I've been struggling with drag and drop on OS X, and at a distance (via helpers) on Linux.

The awt dNd, which is what I've been using, is broadly ok on MacOS X. There seem to be some nasty bugs if you don't automatically use the image that OS X generates -- i.e. if you use the startDrag variant that includes an Image of your own. In that second case it's hard to get the image in the right position under the mouse, and difficult to get the landing point right when you drop. I found a workaround for the second problem (use the image offset, not the original Component offset, when calculating landing), but I never found a way round the first.

I was using the provide-your-own-image variant because dNd on Solaris and Linux is horrible (system-provided behaviour is to drag an opaque icon, nothing to do with the dragged object).

Then I tried to transfer the code to Solaris and to Linux. It was horrible: on Solaris at least you had to use the workaround and the positioning of the image seemed equally flaky. Worse still, there were spurious events claiming multiple dNd events, and I can't remember what else. Linux was similarly awful (one Linux, that is -- another couldn't even do JSplitPanes properly, so it didn't get past first base).

I decided, reluctantly, that this is one area where Apple are likely to have got it right and everybody else (including Sun) got it wrong. There certainly seems to be a Sun-generic bug in awt dNd with a non-system image.

So I concluded that I'd have to do my own dNd if I was going to be able to run it across three platforms and have it look OK. That's what I've been doing for a couple of days. Flyback isn't as pretty as OSX, but the rest seems pretty straightforward.

Richard Bornat

PS If you don't need very precise positioning -- I do -- then the oddness of the landing point is not an issue, and perhaps the mispositioning of the dragged image doesn't matter. So try startDrag with your own generated image (it will come out transparent, I think, on Solaris at least).
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.
References: 
 >OutOfMemoryException During Drag and Drop From a Tree (From: "Shankman, Gordon L." <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.