undo - redo function in a text editor
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.
UndoManager undoManager;
textArea2.getDocument().addUndoableEditListener(this);
textArea2.addFocusListener(this);
public void createUndoManager()
{
undoManager = new UndoManager();
}
public void removeUndoManager()
{
undoManager.end();
}
public void focusGained(FocusEvent fe)
{
createUndoManager();
}
public void focusLost(FocusEvent fe)
{
removeUndoManager();
}
public void undoableEditHappened(UndoableEditEvent uee)
{
undoManager.addEdit(uee.getEdit());
}
public void undoableEditHappened(UndoableEditEvent uee)
{
undoManager.addEdit(uee.getEdit());
}
if ((ae.getSource() == btnUndo) || ae.getActionCommand().equals("Undo"))
{
try
{
undoManager.undo();
}
catch (CannotUndoException cue)
{
Toolkit.getDefaultToolkit().beep();
}
}
}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
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
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
I finally got it fixed about a week ago..I was making it way more difficult than it was.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
do your own homework kid.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337