File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drag and Drop

 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to select and drag text from a JTextField (or any text-like component will do for now) to any other application outside of the VM as if it were a cut or copy operation. I have had no success playing with TransferHandler, but a quick search of this forum suggests no simple solution.

However, I know of one application (Intellij IDA 4.5.3), that claims pure Java, and is capable of such behaviour, but it is closed source. For example, I can select text from the editor, put my mouse over it, the mouse cursor displays an arrow, hold down the left mouse button and drag the text to any text editor (such as notepad on Windows). This behaves as if it were a simple cut/paste operation.

Is this behaviour possible to replicate?
 
Don Kiddick
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly is
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the pointer.

I looked at the example and was able to understand the basics and modify it to suit my needs, but for a JLabel only.

The reason being, when I highlight some text in a JTextField, it acts as if I'm performing a drag operation. As soon as one character is highlighted, I am now dragging and can drop that one character somewhere. I tried fiddling with things to try to allow me to drag only once text has been selected, and the mouse has been released, but I soon found myself writing "spaghetti code" that didn't really work anyway.

Any other tips?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic