java/swing:剪贴板粘贴
我有一个 DropTargetListener 设置,允许我将字符串拖放到 Swing 应用程序的某些表中 - 在拖放时,我解析字符串并将数据插入表中。
我想用剪贴板粘贴(Ctrl-V)做同样的事情。 有哪些文献可以解释如何处理剪贴板粘贴?我正在查看Sun 网站上的一些东西,看起来很奇怪,就像这样应该更简单。
I have a DropTargetListener setup to allow me to drag + drop strings into some tables of my Swing application -- on a drop, I parse the string and insert data into the table.
I would like to do the same thing with a clipboard paste (Ctrl-V). What literature is there to explain how to handle clipboard pastes? I'm looking at some stuff from Sun's website and it seems bizarre, like this should be simpler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bozhidar Batsov 的这个答案是我见过的最好的解决方案,简单且可扩展。添加他的类文件后,这就是我实现他的类的方式
添加其他操作应该非常简单:
Action
类字段,enum Actions
AbstractAction
mouseClicked(MouseEvent e)
方法就这样。我在这里添加细节部分是为了确保我理解它,也是为了让我之后的人清楚地了解需要做什么。不要忘记包含必要的
导入
!This answer by Bozhidar Batsov is the best solution I have seen around, simple and extensible. After adding his class file, this is how I implemented his class
Adding additional actions should be pretty simple:
Action
class field,enum Actions
AbstractAction
with the desired functionsmouseClicked(MouseEvent e)
methodAnd there you go. I added the detail here partly to make sure I understand it, and also to give those after me a clear understanding of what needs to be done. Don't forget to include the necessary
imports
!如 简介 和
ListCutPaste
< a href="http://java.sun.com/docs/books/tutorialJWS/uiswing/dnd/ex6/ListCutPaste.jnlp" rel="nofollow noreferrer">demo,将两者连接起来。 DnD 自动为您获取 CCP。As shown in the intro and the
ListCutPaste
demo, the two are connected. The DnD gets you CCP automatically.相反,我建议您查看 java.awt.datatransfer.Clipboard 类文档。我想这会配合你的 DnD 操作。
I would instead suggest you to take a look at java.awt.datatransfer.Clipboard class documentation. I think it will go along with your DnD operations.