| 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: 19216
|
|
|
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
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: 1791
|
|
|
Read the secton from the Swing tutorial on "Text Component Features" for a working example.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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
|
|
|