This week's book giveaways are in the JBoss and Spring forums.
We're giving away four copies each of JBoss AS 5 Development and Spring Dynamic Modules in Action and have the authors on-line!
See this thread and this one for details.
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
Author

Swing DnD within JTree using Objects?

B Atkins
Greenhorn

Joined: Jun 11, 2009
Messages: 11

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


Two wrongs don't make a right... but three lefts do.
B Atkins
Greenhorn

Joined: Jun 11, 2009
Messages: 11

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.

Two wrongs don't make a right... but three lefts do.
Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 3876

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.

work is the scourge of the drinking class
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
The most intelligent Java IDE

trailboss links:

permaculture
diatomaceous earth
Sepp Holzer
rocket mass heater
raising chickens
cast iron
lawn care