This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Drag and drop problem 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 and drop problem" Watch "Drag and drop problem" New topic
Author

Drag and drop problem

Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
Hello guys! This is my first post on this forum I am a beginner to java! What i want to do is make a drag and drop from a jtree and a JList. The Jtree contains the all file system and want to drop only drop the filename with path to the JList. I found an example of FileTree which uses a custom TreeNode (FileTreeNode) and a custom TreeCellRenderer (FileTreeCellRenderer) i will post the code:



and the other class:




Recently i found something similar drag and drop example which is great example, thanks who did it and i need to use a TransferHandler for both (JTree and JList), Jtree to export and JList to import.

The TransferHandler for JList is this:



and now i take it from that example the TransferHandler for the JTree



The problem is it uses a DeafaultMutableTreeNode and i use a custom TreeNode.



Can anybody can help me to make the userObjectMethod() for my custom FileTreeNode? It doesn`t show the filename and path to the JList when i drop it from the jtree it shows something like this Test.FileTreeNode@1f78ef1 where Test is the name of the application.

Sorry for my english. I hope you get the ideea.

Regards, Calin!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Calin,

I spent a good deal of time last night doing something very similar. The only real difference is my user object wasn't a File. I have it working but the code is a mess and there are specific things it to my project.

What I am going to attempt today is to yank it out into a sample application that I can share with you. I just didn't want you to think your thread is being ignored. But I might not have it until the end of the weekend. I'll just have to see how difficult it night be.

Welcome to JavaRanch!


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

http://www.greggbolinger.com/blog/2008/11/14/1226688420000.html
Bobes Calin
Greenhorn

Joined: Nov 13, 2008
Posts: 14
Thanks Gregg for the example and sorry for the late reply. I still don`t make it work when drop the file to the list is showing the same format file name "Test.FileTreeNode@1f78ef1" and i was tthinking that the "getUserObject()" is responsible for this.

It`s not necessary to use dnd i only want when selecting the files from the JTree to add the path+filename to the JList. I was thinking to make a popup menu when right click the mouse on the node and select for example "insert to list" and insert the path+filename.

It it possible to make it work on FileTreeNode or i have to use DefaultMutableTreeNode to get the corect path+filename?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drag and drop problem