Undo

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Undo

 
0
  #1
Feb 13th, 2005
Hi everyone,

I am trying to add an undo listener to a jtable but could not get it to work. Does anyone know how to add a undo function to a jtable assuming the default cell editor component is a jtextfield?

A small code sample would be helpful

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Undo

 
0
  #2
Feb 13th, 2005
are you wanting to add it to the textfield? If so, all you have to do is create a document from the textfield..

import these:

  1. import javax.swing.undo.*;
  2. import javax.swing.event.*;
  3. import javax.swing.text.*;

add an UndoableEditListener

create an UndoManager as an instance variable

create a Document as an instance variable

then create the document and add the listener to it(That is if you want to add it to a textfield,this is the way I took it)
  1.  
  2. doc = (Document)txtDisplay.getDocument();
  3. doc.addUndoableEditListener(this);

undoable edit event stuff

  1. public void undoableEditHappened(UndoableEditEvent uee)
  2. {
  3. undoManager.addEdit(uee.getEdit());
  4. }

then do the undo and redo like this:

  1. //don't need this method
  2. public void processUndo()
  3. {
  4. try
  5. {
  6. /* call the UndoManagers undo method
  7. */
  8. undoManager.undo();
  9. }
  10. catch (CannotUndoException cre)
  11. {
  12. }
  13.  
  14. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Undo

 
0
  #3
Feb 14th, 2005
Hi everyone,

I already tried that but it does not seem to work for the jtable as i feel it has something to to with the cell renderer

Richard West
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC