Eclipse:选择自动复制到剪贴板

编程入门 行业动态 更新时间:2024-10-28 11:22:45
本文介绍了Eclipse:选择自动复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我喜欢Emacs功能,可以自动将选择内容复制到剪贴板。是否可以在Eclipse上执行相同操作?

I love an Emacs feature to copy selection to clipboard automatically. Is it possible to do the same on Eclipse?

环境:Windows XP,Helios

Environment: Windows XP, Helios

推荐答案

要将一个字符串从Eclipse复制到剪贴板,可以使用

To copy a String from Eclipse to the clipboard, you can use

void copyToClipboard (String toClipboard, Display display){ String toClipboard = "my String"; Clipboard clipboard = new Clipboard(display); TextTransfer [] textTransfer = {TextTransfer.getInstance()}; clipboard.setContents(new Object [] {toClipboard}, textTransfer); clipboard.dispose(); }

然后,您可以从 MouseAdapter 或 KeyAdapter ,具体取决于您要从中获取字符串的位置。在你的情况下,它可以是 MouseAdapter ,它监听双击,获取文本的当前光标位置,标记该字,然后将该字符串添加到剪贴板。

Then you can call this method from a MouseAdapter or KeyAdapter, depending on where you want to get your String from. In your case it could be MouseAdapter, which listens to doubleclicks, gets the current cursor position of the text, marks the word and then adds the String to the clipboard.

编辑回答一个问题:您可以设置自己的 MouseAdapater 并将其附加到您喜欢的按钮,文本字段或whateer 。这是一个按钮的例子:

edit to answer a question: You can set up your own MouseAdapater and attach it to buttons, text fields or whateer you like. Here's an example for a button:

Button btnGo1 = new Button(parent, SWT.NONE); btnGo1.setText("Go"); btnGo1.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { //do what you want to do in here } });

如果要实现mouseUp和mouseDown事件,也可以添加 MouseListener 而不是适配器。适配器的唯一优点是,您不必重写界面的其他方法。

If you want to implement mouseUp and mouseDown events, too, you can just add MouseListenerinstead of the Adapter. The only advantage of the Adapter is, that you don't have to override the other methods of the interface.

由于原来的问题是自动获取编辑器的文本:从编辑器中获取选择的方式说明了这里。

Since the original question was to automatically get the selection of the text of an editor: the way to get the selection from an editor is explained here.

更多推荐

Eclipse:选择自动复制到剪贴板

本文发布于:2023-11-14 02:30:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剪贴板   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!