I am trying to implement undo functionality in JTextArea. Googled for tutorial and followed one of the tutorial and wrote the below code. The event is triggered when Ctrl+Z key is pressed. Its not working for me. Am I missing something?
private void undoActionPerformed(java.awt.event.ActionEvent evt) {
Document doc = editorTextArea.getDocument();
final UndoManager undo = new UndoManager();
doc.addUndoableEditListener(new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
undo.addEdit(e.getEdit());
}
});
}
From you’re example, it’s difficult to know how much you’ve done, but I was able to get this to work…