Tutorial :Dragging text from a Word document to a Java text component?



Question:

When you drag a block of text from a Word document into a Java text component, the text is removed from the Word document. This is obviously undesirable in some cases. Is there a way I can prevent Word from removing the text, while still copying it into the Java text component?


Solution:1

Return false from TransferHandler.importData(JComponent comp,Transferable t). You can keep the data but you tell the drag system that you didn't take it.


Solution:2

Try holding down ALT, CTL, or SHIFT (I forget) while dragging. I believe this changes the default behavior of your cursor from cut -> copy.

You may be able to set the default Drop action in your JText component to only allow copy, I know you can do that in SWT.


Solution:3

I think that is the default behavior (This would happen even if you drag the text from one Word document to another one). You may want to keep the 'Ctrl' key pressed to achieve the desired results (Ctrl + Drag forces a copy operation).


Solution:4

Can't you make use of copy/paste? Highlighting and dragging anything around in a Word document or out of a word document into another document or text area is the equivalent of cutting and pasting. Ctrl + C (copy) and Ctrl + V (paste) works just as fast.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »