• Post Reply Bookmark Topic Watch Topic
  • New Topic

DnD with JLabel subclass

 
Josh Sandeman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to enable Drag-N-Drop support between two classes that are each subclasses of JLabel. They both have member variables of type String whose contents I am trying to transfer. Each has public get & set methods for the member variable, and both are given default TransferHandler objects whose constructors are passed the name of the property. But when I attempt the DnD, I get an "Invocation failed" error. The Java Tutorial on DnD does not seem to specify additional requirements for this scenario, so I'm a bit stumped at the moment about what I am missing or doing wrong.

Thanks!
Josh
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read Me.
 
Josh Sandeman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm. Okay, well, I am using the Java 5 environment. I am able to initiate a drag, and the error I mentioned occurs when I perform the drop on the target. The property in both the source and target classes is a String named "moduleName".

I thus set up the TransferHandler like:

moduleLabel.setTransferHandler(new TransferHandler("moduleName"));

The ENTIRE error message following the drop is as I mentioned: Invocation failed. There is no stack trace to report.

I'm not sure what else to add, since it's a pretty simple scenario.

Josh
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the DragAndDrop tutorial, in the section "Specifying The Data Format", check the second paragraph (starting with "When using the property name form...") through the third. These are special properties. I set up a test app to duplicate the "Invocation failed" exception. Then looked in the TransferHandler source code and found the string in an exception handler in the importData method. I copied some of the code into CustomHandler and added a couple of System.out.println statements so it prints out the properties that will work for JLabel. Looks like we're in Beans country...
Conclusion: the properties come from the class api and not from our code.
 
Josh Sandeman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Thanks so much. I apologize for the slow response... I've been distracted. I have since decided to use custom handlers and DataFlavors, since that seems to be the Tao of DnD.

Cheers!
Josh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!