This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Drag cursor not changing, but drop succeeding.

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
B Atkins
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic