这真让我困惑。
JTextComponent
为此,我添加了一个右键单击“剪切\复制\粘贴”菜单,使用jpopp菜单和
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());
final ActionListener textFieldListener = new ActionListener() {
@Override public void actionPerformed(ActionEvent e){someGlobalFunction(textComponent.getText());
}
};
...
cutItem.addActionListener(textFieldListener );
copyItem.addActionListener(textFieldListener );
pasteItem.addActionListener(textFieldListener );
然而,我唯一能抓住的文本是它原来所在的字符串
之前
我剪切\粘贴到组件中,而不是之后。
有什么明显的解决办法吗?