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();
}
}
}