are you wanting to add it to the textfield? If so, all you have to do is create a document from the textfield..
import these:
import javax.swing.undo.*;
import javax.swing.event.*;
import javax.swing.text.*;
add an UndoableEditListener
create an UndoManager as an instance variable
create a Document as an instance variable
then create the document and add the listener to it(That is if you want to add it to a textfield,this is the way I took it)
doc = (Document)txtDisplay.getDocument();
doc.addUndoableEditListener(this);
undoable edit event stuff
public void undoableEditHappened(UndoableEditEvent uee)
{
undoManager.addEdit(uee.getEdit());
}
then do the undo and redo like this:
//don't need this method
public void processUndo()
{
try
{
/* call the UndoManagers undo method
*/
undoManager.undo();
}
catch (CannotUndoException cre)
{
}
}