| | |
Undo
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
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
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
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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:
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)
undoable edit event stuff
then do the undo and redo like this:
import these:
Java Syntax (Toggle Plain Text)
import javax.swing.undo.*; import javax.swing.event.*; 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)
doc = (Document)txtDisplay.getDocument(); doc.addUndoableEditListener(this);
undoable edit event stuff
Java Syntax (Toggle Plain Text)
public void undoableEditHappened(UndoableEditEvent uee) { undoManager.addEdit(uee.getEdit()); }
then do the undo and redo like this:
Java Syntax (Toggle Plain Text)
//don't need this method public void processUndo() { try { /* call the UndoManagers undo method */ undoManager.undo(); } catch (CannotUndoException cre) { } }
![]() |
Similar Threads
- News Story: Get Out of Trouble With Gmail's New "Undo Send" Feature (Pay-Per-Click Advertising)
- tkinter undo/redo (Python)
- undo - redo function in a text editor (Java)
- undo (Visual Basic 4 / 5 / 6)
- undo/redo help!!! (ASP.NET)
Other Threads in the Java Forum
- Previous Thread: Confused writing a Java Class
- Next Thread: Zip And Jar
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui hql html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






