This really puzzles me.
I have a JTextComponent
for which I've added a right-click cut\copy\paste menu using a JPopupMenu and 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());
For each action I've added an action listener which grabs the JTextComponent's text, which I want to use in a function.
final ActionListener textFieldListener = new ActionListener() {
@Override public void actionPerformed(ActionEvent e){someGlobalFunction(textComponent.getText());
}
};
...
cutItem.addActionListener(textFieldListener );
copyItem.addActionListener(textFieldListener );
pasteItem.addActionListener(textFieldListener );
However, the only text I can get hold on is the String which it was before I cut\paste into the component, not after.
Is there any obvious solution for this?