File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to add Undo and Redo actions to JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How to add Undo and Redo actions to JPanel" Watch "How to add Undo and Redo actions to JPanel" New topic
Author

How to add Undo and Redo actions to JPanel

Digen Mahara
Greenhorn

Joined: Dec 23, 2011
Posts: 23

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 !!!


To every Tunnel there is always a way out
So keep Trying...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32667
    
    4
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
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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

Joined: Oct 13, 2005
Posts: 32667
    
    4
I was mistaken, obviously. Sorry.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add Undo and Redo actions to JPanel
 
Similar Threads
Undo/Redo using SWING
Data structure in real world
Undo and Redo in JText viewer?
How to implment Undo/Redo for a editor
Trigger Undo from Javascript?