简体   繁体   English

将文本从Word文档拖到Java文本组件?

[英]Dragging text from a Word document to a Java text component?

When you drag a block of text from a Word document into a Java text component, the text is removed from the Word document. 当您将文本块从Word文档拖到Java文本组件中时,该文本将从Word文档中删除。 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? 有什么方法可以防止Word删除文本,同时仍将其复制到Java文本组件中?

Try holding down ALT, CTL, or SHIFT (I forget) while dragging. 拖动时尝试按住ALT,CTL或SHIFT(我忘记了)。 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. 您也许可以在JText组件中将默认的Drop动作设置为仅允许复制,我知道您可以在SWT中做到这一点。

Return false from TransferHandler.importData(JComponent comp,Transferable t) . TransferHandler.importData(JComponent comp,Transferable t)返回false You can keep the data but you tell the drag system that you didn't take it. 您可以保留数据,但可以告诉拖动系统您没有使用它。

I think that is the default behavior (This would happen even if you drag the text from one Word document to another one). 我认为这是默认行为(即使您将文本从一个Word文档拖到另一个文档中,也会发生这种情况)。 You may want to keep the 'Ctrl' key pressed to achieve the desired results (Ctrl + Drag forces a copy operation). 您可能需要按住“ Ctrl”键来获得所需的结果(Ctrl + Drag强制执行复制操作)。

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. 突出显示并拖动Word文档中的任何内容或将其拖出Word文档中的内容到另一个文档或文本区域中,等同于剪切和粘贴。 Ctrl + C (copy) and Ctrl + V (paste) works just as fast. Ctrl + C(复制)和Ctrl + V(粘贴)的运行速度一样快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM