944,070 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3203
  • Java RSS
Feb 13th, 2005
0

Undo

Expand Post »
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
Similar Threads
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Feb 13th, 2005
0

Re: Undo

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:

Java Syntax (Toggle Plain Text)
  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)
Java Syntax (Toggle Plain Text)
  1.  
  2. doc = (Document)txtDisplay.getDocument();
  3. doc.addUndoableEditListener(this);

undoable edit event stuff

Java Syntax (Toggle Plain Text)
  1. public void undoableEditHappened(UndoableEditEvent uee)
  2. {
  3. undoManager.addEdit(uee.getEdit());
  4. }

then do the undo and redo like this:

Java Syntax (Toggle Plain Text)
  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. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 14th, 2005
0

Re: Undo

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: applet , Runnable interface and problems
Next Thread in Java Forum Timeline: Zip And Jar





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC