views:

213

answers:

4

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?

+4  A: 

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.

Gandalf
+1  A: 

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).

Vinnie
A: 

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.

Unfortunately, I can't force any particular behavior from the user, which is why I'm trying to find a programmatic solution. :o)
Amanda S
Then, I think you're stuck. Word's default behavior is that drag 'n drop is the equivalent of cut/paste unless you use a hot key to override it. Otherwise, you have to find a way to go in and modify Word itself which is probably a no-no. :-/ Perhaps the best solution is to include text warnings encouraging copy/paste.
I feel like there must be *some* way to override this behavior on the recieving end... I can drag from a Word document into a text box on a web browser and it doesn't cut the text from the Word document.
Amanda S
+3  A: 

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.

Clint
Caveat: This requires implementing one's own TransferHandler.
Amanda S
Corrected in answer.
Clint
But thanks, this is exactly what I was looking for.
Amanda S