aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drag cursor not changing, but drop succeeding. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drag cursor not changing, but drop succeeding." Watch "Drag cursor not changing, but drop succeeding." New topic
Author

Drag cursor not changing, but drop succeeding.

B Atkins
Greenhorn

Joined: Jun 11, 2009
Posts: 11
I've got a JTree as a drop target. I can drag leaf elements around within the tree just fine, and the cursor changes as appropriate when it's over a legal vs. illegal drop location. I have another drag source which is a JList in the same layout. I can drag from there and successfully drop onto the JTree (the list is NOT a drop target, btw). However, the cursor never changes when the drag is from the JList, it always shows a no-drop icon. I can drop, and the elements are successfully copied, but the cursor never changes. What am I doing wrong here?

I also want to control the type of cursor shown based on the drag source. If the drag comes from the JList, it will only ever be a copy, never a move. Hence, I want to always show the copy cursor, regardless of what meta-keys the user may be using, attempting to change the type of drag and drop. The intra-JTree DnD, however, can be either a move or copy, as normal. Can I accomplish this at the Swing level, or do I have to resort to an AWT solution? Can the two live together?

Thanks!
Brian


Two wrongs don't make a right... but three lefts do.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Can I accomplish this at the Swing level,
Yes.
or do I have to resort to an AWT solution?
No.
Can the two live together?
Sometimes, yes.

If you want the cursor to show the copy_cursor inside/over the list you can return true from canImport and override importData to return false inside listHandler.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

B Atkins wrote: Can the two live together?

As you probably already know AWT is "heavyweight" where as Swing is it's "lightweight" cousin.
Check out this article on why it's not a good idea to mix up the two.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
B Atkins
Greenhorn

Joined: Jun 11, 2009
Posts: 11
Thanks! I discovered that limiting the source to just COPY will get you the COPY cursor, like you demonstrated. Somewhere along the line the cursor remaining no-drop even when over a valid drop zone, and even with a successful drop, went away.

I already have a working system with a somewhat complex transfer, in that objects coming from the JList are one type, while objects moving around in the JTree are another. When the transferable comes in from the JList, it gets converted to the appropriate type for insertion into the JTree. I do this with a custom DataFlavor and Transferable. The problem was just with the cursor not behaving correctly, which has since resolved.
 
 
subject: Drag cursor not changing, but drop succeeding.