Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drag and drop problem

 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
 
Bobes Calin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic