View Single Post
  #4 (permalink)  
Old 07-02-2008, 01:25 AM
serjant's Avatar
serjant serjant is online now
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 329
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
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
Code:
JTextArea textArea=new JTextArea();
Code:
//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:
Code:
//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:
Code:
//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){ } }
Reply With Quote