For my diploma work at university i made java editor,so to each of JMenutItem pass with ActionListener,I attach the code in that case if you use JTextArea
actionPerformed(ActionEvent e) for cut command:
Assuming that
JTextArea textArea=new JTextArea();
//cut command
if(e.getActionCommand().equals("Cut")){
String selection=textArea.getSelectedText();
if(selection==null){
return;
}
StringSelection clipString=new StringSelection(selection);
clipboard.setContents(clipString,clipString);
textArea.replaceSelection("");
}
actionPerformed(ActionEvent e) for copy command:
//copy command
if(e.getActionCommand().equals("Copy")){
String selection =textArea.getSelectedText();
if(selection==null){
return;
}
StringSelection clipString=new StringSelection(selection);
clipboard.setContents(clipString, clipString);
}
actionPerformed(ActionEvent e) for paste command:
//paste command
if(e.getActionCommand().equals("Paste")){
Transferable clip_data=clipboard.getContents(this);
try{
String clip_string=(String)clip_data.getTransferData(DataFlavor.stringFlavor);
textArea.replaceSelection(clip_string);
}catch(Exception excpt){
}
}