This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implment Undo/Redo for a editor

 
Dinesh Bang
Ranch Hand
Posts: 52
  • 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
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • 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
  • 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: 2703
10
  • 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
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • 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():
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!