943,513 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 6399
  • Java RSS
Dec 22nd, 2004
0

undo - redo function in a text editor

Expand Post »
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.


Java Syntax (Toggle Plain Text)
  1. UndoManager undoManager;


Java Syntax (Toggle Plain Text)
  1. textArea2.getDocument().addUndoableEditListener(this);
  2. textArea2.addFocusListener(this);


Java Syntax (Toggle Plain Text)
  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. }


Java Syntax (Toggle Plain Text)
  1. public void undoableEditHappened(UndoableEditEvent uee)
  2. {
  3. undoManager.addEdit(uee.getEdit());
  4. }


Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jan 3rd, 2005
0

Re: undo - redo function in a text editor

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jan 3rd, 2005
0

Re: undo - redo function in a text editor

I finally got it fixed about a week ago..I was making it way more difficult than it was.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Sep 12th, 2006
0

Re: undo - redo function in a text editor

Please Sand me your all code of the editor.
Plz
Plz
Thanks
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Bhavna.ce is offline Offline
1 posts
since Sep 2006
Sep 12th, 2006
0

Re: undo - redo function in a text editor

do your own homework kid.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: New 2 JAVA
Next Thread in Java Forum Timeline: event code not working





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC