Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add Undo and Redo actions to JPanel

 
Digen Mahara
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a paint application and want to add undo and redo functions to it how can I do this

I have used UndoManager class with TextComponents but really confused with Containers like JPanel where you actually draw images



Please Help !!!
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Undo Manager appears only to work with text components.
How are you drawing your images? Do you have some sort of ImageComponent class or similar? Can you put ImageComponents into some sort of List and go back and forth along the List?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Undo Manager appears only to work with text components.


Not at all. UndoManager can work with any kind of edits at all. It's just that you have to write a subclass of UndoableEdit which essentially stores the "before" and "after" states in such a way that the undo() and redo() methods modify the view appropriately. For example an edit for a checkbox might look like this (not all required methods implemented):
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was mistaken, obviously. Sorry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic