• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing DnD within JTree using Objects?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to be able to drag leave nodes between non-leaf nodes within the same JTree. When I try to implement Swing DnD using a TransferHandler, the drag never seems to initiate (no indication of the drag appears on the cursor or in the JTree). When I implement it using the more laborious AWT methods, I can get it to work. Is there a way to force Swing to recognize a DnD gesture within a single component?

In a related question, I want to initiate the drag when the user has selected leaf nodes, and only from the same parent. If a user selects a combination of nodes that includes a non-leaf node, or nodes from different parents, I'd like to have no DnD initiated in the first place (e.g. no cursor change, no visual indication of the drag initiating, rather than just rejecting the drop everywhere).

Thanks!
Brian

 
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
Ok, solved both problems. I was not specifying allowed actions by overriding getSourceActions(), and if you return null from createTransferable, the drag doesn't initiate.
 
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
Well done, and welcome to the Ranch.
We have a GUI related forum here, which would be a more appropriate place for this thread. I will move it for you, so future users, with the same problem can benefit from your solution.
 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic