undo - redo function in a text editor

Thread Solved

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

undo - redo function in a text editor

 
0
  #1
Dec 22nd, 2004
I have a text editor I've been working on, and I'm having some trouble with the undo/redo functions... It doesn't work, and I don't know what's wrong with it. I posted all of my code dealing with the undo function. I know it's a lot, but maybe you wont mind helping me. Any suggestions will help.


  1. UndoManager undoManager;


  1. textArea2.getDocument().addUndoableEditListener(this);
  2. textArea2.addFocusListener(this);


  1. public void createUndoManager()
  2. {
  3. undoManager = new UndoManager();
  4. }
  5.  
  6. public void removeUndoManager()
  7. {
  8. undoManager.end();
  9. }
  10. public void focusGained(FocusEvent fe)
  11. {
  12. createUndoManager();
  13. }
  14. public void focusLost(FocusEvent fe)
  15. {
  16. removeUndoManager();
  17. }
  18. public void undoableEditHappened(UndoableEditEvent uee)
  19. {
  20. undoManager.addEdit(uee.getEdit());
  21. }


  1. public void undoableEditHappened(UndoableEditEvent uee)
  2. {
  3. undoManager.addEdit(uee.getEdit());
  4. }


  1. if ((ae.getSource() == btnUndo) || ae.getActionCommand().equals("Undo"))
  2. {
  3. try
  4. {
  5. undoManager.undo();
  6. }
  7. catch (CannotUndoException cue)
  8. {
  9. Toolkit.getDefaultToolkit().beep();
  10. }
  11. }
  12. }
Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: undo - redo function in a text editor

 
0
  #2
Jan 3rd, 2005
Hi everyone,

You are resetting your UndoManager class every time so there is always nothing to undo. Basically remove the createUndoManager() function and create that class once as a global class with a global instance only once.

Don't forget the import stsement for the undo class as well

Richard West
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: undo - redo function in a text editor

 
0
  #3
Jan 3rd, 2005
I finally got it fixed about a week ago..I was making it way more difficult than it was.
Quick reply to this message  
Join Date: Sep 2006
Posts: 1
Reputation: Bhavna.ce is an unknown quantity at this point 
Solved Threads: 1
Bhavna.ce Bhavna.ce is offline Offline
Newbie Poster

Re: undo - redo function in a text editor

 
0
  #4
Sep 11th, 2006
Please Sand me your all code of the editor.
Plz
Plz
Thanks
Quick reply to this message  
Join Date: Nov 2004
Posts: 6,464
Reputation: jwenting is a name known to all jwenting is a name known to all jwenting is a name known to all jwenting is a name known to all jwenting is a name known to all jwenting is a name known to all 
Solved Threads: 233
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: undo - redo function in a text editor

 
0
  #5
Sep 12th, 2006
do your own homework kid.
42
Quick reply to this message  
Closed Thread

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 5272 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC