什么是切的最好方式,复制和粘贴在Java中? [英] What is the best way to cut, copy, and paste in Java?
问题描述
我已经创建使用Swing的一个文本区域(JTextArea中)的应用程序。我想创建一个编辑菜单的选项包括削减和从剪贴板复制从文本区文本,粘贴文本到文本区域。
I've created an application using Swing with a text area (JTextArea). I want to create an "edit" menu, with options to cut and copy text from the text area, and paste text from the clipboard into the text area.
我见过一对夫妇方法可以做到这一点,但我想知道的最佳方式是什么。我应该如何实现剪切/复制/粘贴?
I've seen a couple of ways to do this, but I wanted to know what the best way is. How should I implement the cut/copy/paste?
推荐答案
我会亲自选择重新使用标准的剪切,复制和粘贴操作。这是在 Swing拖动和拖放教程的所有解释:增加剪切,复制和粘贴一>。了解文本组件的部分是最相关的为您服务。该页面的某些code的快速复制粘贴:
I would personally opt for re-using the standard cut, copy and paste actions. This is all explained in the Swing drag-and-drop tutorial: adding cut, copy and paste. The section about text components is the most relevant for you. A quick copy-paste of some code of that page:
menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
menuItem.setText("Copy");
menuItem.setMnemonic(KeyEvent.VK_C);
这篇关于什么是切的最好方式,复制和粘贴在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!