Revision as of 07:56, 4 December 2010 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/**
 * 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

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang