JTextArea setText() & UndoManager

前端 未结 5 495
夕颜
夕颜 2020-12-10 21:43

I\'m using an UndoManager to capture changes in my JTextArea.

The method setText() however deletes everything and then pastes

5条回答
  •  难免孤独
    2020-12-10 22:08

    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.

提交回复
热议问题