记事本里的撤销功能怎么做啊 用javaSE
解决方案 »
- Java编码问题
- 有关类的继承与接口实现同时存在的问题
- 打成jar包后运行到数据库部分出错
- 谁来帮我讲解一下这道题~~~谢谢
- JAVA中的正则表达式怎么用?
- 问一个关于输入框JFormattedTextField和MaskFormatter的问题
- !!!如何将两个byte[]连接成一个byte[]
- 关于数据字典????
- 我用Jet把java编译成本地可执行的程序了,可是换一台机子又不可以运行了,说是需要有jet的运行坏环境,那还不如安装JVM呢。求高手教我怎
- java.io.IOException: Not an ISO 8859_1 character:星
- jpa onetomany 查询子集合如何加条件
- equals " " 和 " " equalse有区别吗
2.代码如下:
// ---------------创建撤消操作管理器
protected UndoManager undo = new UndoManager();
protected UndoableEditListener undoHandler = new UndoHandler();
// 撤消
else if (e.getSource() == mEdit_Undo || e.getSource() == popupMenu_Undo || e.getSource() == undoButton) {
Text.requestFocus();
if (undo.canUndo()) {
try {
undo.undo();} catch (CannotUndoException ex) {
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}if (!undo.canUndo()) {
mEdit_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);}
}
}
3.test测试
要么把每个文本修订动作、位置、增量内容记录下来,Undo的时候反向操作。
addUndoableEditListener(UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.
如果你可以接受一个字一个字的测销,
那Swing自带的UndoManager就很适合你否则,你要自己写个UndoManager了