我在从 JTextComponent 获取复制和粘贴方法时遇到一些问题
对于我的程序,我有一个字符串数组,它们将作为菜单选项。 “复制”和“粘贴”是其中两个。
else if (e.getActionCommand().equalsIgnoreCase("Copy"))
{
JTextArea a = new JTextArea();
a.setEditable(true);
a.copy();
}
else if (e.getActionCommand().equalsIgnoreCase("Paste"))
{
JTextArea a = new JTextArea();
a.setEditable(true);
a.getSelectedText();
a.paste();
}
我没有收到错误消息,但它不起作用。任何帮助将不胜感激
最佳答案
每次您想要执行操作时,都会创建一个新的 JTextArea
实例。
这些并不代表屏幕上的实际内容。相反,与实例变量交互或将屏幕上的 JTextArea
实例作为参数传递
关于java - 在java中实现复制/粘贴操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18039725/