I\'m using an UndoManager to capture changes in my JTextArea.
UndoManager
JTextArea
The method setText() however deletes everything and then pastes
setText()
A simple workaround is to use replaceRange:
area.replaceRange(newText, 0, area.getText().length());
This counts as a single edit, so is undone in one step.