I have created a Swing application and I'm trying to configure Drag and Drop support for a JTextArea. There are two capabilities I need for this object, I want it to accept text pasted into it from the clipboard and I also want to accept files dropped onto the object, grab the file name and then send that to another routine which will open the file, read the contents, and perform some work.
However, I cannot even get past first base on this. I have created a class of transferhandler as follows:
I have created an object using that class as the type and have set the JTextArea to use that transferhandler:
Now....if I comment out the second line above so the JTextArea uses the default transferhandler the JTextArea will accept drag and drop and the file name will appear in the JTextArea - which is not what I want.
When I set the object to use MyTransferHandler it rejects all drag and drops.
Please note that within the new class I have Println commands which I thought would send messages out to the console when that piece of code was executed - but nothing ever appears on the console which indicates to me the code is not being executed???
Please help, I have spent hours on this and don't know what to try next!
I'm not sure how to combine it into one, but I guess you would need to get the data flavor to determine which code to execute.
Thank you for replying, the link you provided seems to lead back to this thread. I have been through several tutorials and examples but.....am I correct in assuming that if the code was being executed, my println statements would be working? I am wondering if I am missing some additional link between the JTextArea and the new transferhandler class. It appears the Transferhandler code is not being executed.
Yes, I posted the question in four different forums on the web assuming that different developers are in each forum and I would get four different answers, some of which would be easier to follow and might lead to a solution, whereas some forums might yield no answers at all.
I read your link about cross posting to other forums. I tend to approach every problem with great parallelism. I try a dozen different solutions, read a dozen different tutorials, visit two dozen different web sites for answers, and consult (hopefully) several dozen different experts. I didn't mean to break any rules.