这真让我感到困惑。将文本粘贴到JTextComponent(Java)之后获取操作
我有一个JTextComponent
我已经使用JPopupMenu和DefaultEditorKit.Cut\Copy\PasteAction()
添加了一个右键单击剪切\复制\粘贴菜单。
JMenuItem cutItem = new JMenuItem(new DefaultEditorKit.CutAction());
JMenuItem copyItem = new JMenuItem(new DefaultEditorKit.CopyAction());
JMenuItem pasteItem = new JMenuItem(new DefaultEditorKit.PasteAction());
因为我已经添加了一个动作监听器抓住的JTextComponent的文字,我想在一个函数中使用的每个动作。
final ActionListener textFieldListener = new ActionListener() {
@Override public void actionPerformed(ActionEvent e){someGlobalFunction(textComponent.getText());
}
};
...
cutItem.addActionListener(textFieldListener);
copyItem.addActionListener(textFieldListener);
pasteItem.addActionListener(textFieldListener);
不过,我可以弄个上唯一的文本是它是之前我砍\粘贴到组件,而不是后面的字符串。
有没有明显的解决方案呢?
这个伎俩! – 2010-06-02 19:54:35