当前位置: 技术问答>java相关
(SOS)如何实现CTR_Z的功能
来源: 互联网 发布时间:2015-09-03
本文导语: 如何在文本编辑器中实现ctr-z的功能请附上源码 | java中有一个类可以实现: import javax.swing.event.*; import javax.swing.undo.*; protected UndoManager undo = new UndoManager(); protected UndoableEditListener undoHandle...
如何在文本编辑器中实现ctr-z的功能请附上源码
|
java中有一个类可以实现:
import javax.swing.event.*;
import javax.swing.undo.*;
protected UndoManager undo = new UndoManager();
protected UndoableEditListener undoHandler = new UndoHandler();
加上内部类class UndoHandler implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent uee) {
undo.addEdit(uee.getEdit());
}
}
在jTextArear1.上加
jTextArea1.getDocument().addUndoableEditListener(undoHandler);
import javax.swing.event.*;
import javax.swing.undo.*;
protected UndoManager undo = new UndoManager();
protected UndoableEditListener undoHandler = new UndoHandler();
加上内部类class UndoHandler implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent uee) {
undo.addEdit(uee.getEdit());
}
}
在jTextArear1.上加
jTextArea1.getDocument().addUndoableEditListener(undoHandler);