This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to implment Undo/Redo for a editor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to implment Undo/Redo for a editor" Watch "How to implment Undo/Redo for a editor" New topic
Author

How to implment Undo/Redo for a editor

Dinesh Bang
Ranch Hand

Joined: Jun 15, 2006
Posts: 52
Hi Ranchers,

I am looking to implement the undo/redo functionality for my custom editor. Any idea's how to achieve that ?


SCJP 1.4,SCBCD 1.3, SCWCD 1.5, ???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Each JTextComponent (including JTextArea and JTextField) have a Document. To this Document you can attach a UndoableEditListener. Combine this with an UndoManager.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dinesh Bang
Ranch Hand

Joined: Jun 15, 2006
Posts: 52
Thanks for quick response

Just to add up, Is there a generic way to handle Undo/Redo for whole perspective.
In my application I will be required to have it on all the views, project explorer ,editors etc.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2155
    
    7
Read the secton from the Swing tutorial on "Text Component Features" for a working example.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Dinesh Bang wrote:Just to add up, Is there a generic way to handle Undo/Redo for whole perspective.
In my application I will be required to have it on all the views, project explorer ,editors etc.

You should still use UndoableEdit and UndoManager, but you must handle your own events that will create an UndoableEdit. Hint: extend AbstractUndoableEdit and override undo() and redo():
 
 
subject: How to implment Undo/Redo for a editor
 
Similar Threads
Data structure in real world
What UML Tool(s) are you using for SCEA Beta Part II?
How do I get an UndoableEdit to absorb another UE?
Do multiple-step enabled Undo/Redo JButton on toolsbar?
Undo and Redo in JText viewer?