Search code examples
javaswingjtextarea

Get a whole history of changes from JTextArea


There is a possibility to get a list of changes in JTextArea in simple way?

I mean that I want to retrieve all text which were typed/showed in JTextArea, something like ReDo/UnDo. Have the possibility to back, like "CTRL + Z"


Solution

  • Back in the days I have used UndoManager to manage swing text component changes.

    You can find api here: Oracle JavaDoc UndoManager

    And usage example here: Java2s example UndoManager

    HTH


    Update:

    UndoManager extends CompoundEdit which declares a protected Vector "edits" of UndoableEdit objects.

    You could get access to that Vector, for listing changes, by writing a class that extends UndoManager and provides public getter metod list getChangesVecor.