/**
 * Add the undo and redo functionality for text area or text field.
 * Returned undoManager is used for undo and redo operations.
 * @param compt
 * @return
 */
public static javax.swing.undo.UndoManager guiGetUndoManager(javax.swing.text.JTextComponent compt) {
	final javax.swing.undo.UndoManager undoManager = new javax.swing.undo.UndoManager();
	compt.getDocument().addUndoableEditListener(
			new javax.swing.event.UndoableEditListener() {
				public void undoableEditHappened(javax.swing.event.UndoableEditEvent e) {
					undoManager.addEdit(e.getEdit());
				}
			});
	return undoManager;
}


Back to JavaHowTo

Alumni Liaison

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett