Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Drag and Drop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drag and Drop" Watch "Drag and Drop" New topic
Author

Drag and Drop

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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?


Tony Morris
Java Q&A (FAQ, Trivia)
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Certainly is
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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
 
subject: Drag and Drop