File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to implment Undo/Redo for a editor

 
Dinesh Bang
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am looking to implement the undo/redo functionality for my custom editor. Any idea's how to achieve that ?
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each JTextComponent (including JTextArea and JTextField) have a Document. To this Document you can attach a UndoableEditListener. Combine this with an UndoManager.
 
Dinesh Bang
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the secton from the Swing tutorial on "Text Component Features" for a working example.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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():
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic