- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 UndoManager在我的 Swing 应用程序中。如果在 UndoManager 上调用了 undo()
、redo()
、addEdit()
或其他方法,Undo 和 Redo 按钮最终必须是启用或禁用。
我找不到对这些方法调用使用react的方法。似乎没有为此目的实现观察者或监听器模式。
并且每次调用 UndoManager 方法时更新 Undo 和 Redo 按钮的启用属性...这不是最佳实践吗?!
一个例子:
在这两种情况下,都必须启用撤消按钮(如果尚未启用)。我需要一种方法来应对所有这些 UndoManager 中的更改!
最佳答案
您可以将监听器添加到撤消和重做按钮。 UndoManager 不知道您正在使用哪些 Swing 组件来撤消或重做。
这是一个 snippet显示撤消按钮的按钮监听器。
// Add a listener to the undo button. It attempts to call undo() on the
// UndoManager, then enables/disables the undo/redo buttons as
// appropriate.
undoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
try {
manager.undo();
} catch (CannotUndoException ex) {
ex.printStackTrace();
} finally {
updateButtons();
}
}
});
// Method to set the text and state of the undo/redo buttons.
protected void updateButtons() {
undoButton.setText(manager.getUndoPresentationName());
redoButton.setText(manager.getRedoPresentationName());
undoButton.getParent().validate();
undoButton.setEnabled(manager.canUndo());
redoButton.setEnabled(manager.canRedo());
}
关于java - 对 UndoManager 的观察,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12534559/
HTML5 规范提到了一个 UndoManager,它可用于查询用户编辑过的文档的先前状态 (http://www.whatwg.org/specs/web-apps/current-work/#un
我使用 UndoManager在我的 Swing 应用程序中。如果在 UndoManager 上调用了 undo()、redo()、addEdit() 或其他方法,Undo 和 Redo 按钮最终必须
我有 3 个 MOC。 MainThread MOC 显示内容(使用 undomanager) 后台保存 MOC 以将数据保存到光盘(连接到存储) Backgorund-update MOC 从服务器
我正在使用 UndoManager 来捕获我的 JTextArea 中的更改。 setText() 方法会删除所有内容,然后粘贴文本。当我撤消时,我首先看到一个空白区域,然后它会显示它之前的文本。 如
我对 ACE 很陌生编辑器和 javascript 一般情况下,除了以下内容之外,我已经设法实现了大部分我想要的: 我想启用或禁用“保存”按钮,具体取决于是否对文档进行了未完成的修改,并且我已尝试通过
我希望能够从我的文档模型中访问 UndoManager,这样我就可以在模型中注册撤消操作: // Assume I've extended MyDocument to conform to Refer
我有一个名为 appointment 的 NSManagedObject,我编辑了它的属性。如果我的用户按下取消,我想撤消所有这些编辑。 如果我这样做(示例代码) [[appointment mana
使用 ACE Editor , 它看起来好像使用 editor.getSession().getUndoManager() 和一个已经用 editor.setSession() 设置的 session
我有一个 JTextArea 和一个 JComboBox 允许我循环浏览各种打开的文件 - JTextArea 的内容随着我的选择而改变一个不同的文件。我试图为每个文件维护一个不同的撤消缓冲区,并为每
我正在尝试在我的模型中实现撤消/重做。所以我让我的模型类成为 NSResponder 的子类,然后实现了以下内容: 注意:此代码是根据评论后的更多研究编辑的 func setAnnotations(_
我正在努力向使用 undoManager 的 Swift 库添加一些测试。在库的演示中,将以下打印添加到 viewDidAppear: 会导致打印 NSUndoManagerObject。 overr
我对如何在 Firefox 中使用 undoManager 有点困惑。根据Mozilla , Firefox 20 现在支持它,但我不知道在哪里。我已经在 document、Objects 等下进行了
我想在我的应用程序中应用撤消和重做操作。我阅读了苹果文档并用谷歌搜索了它,但没有得到正确的解决方案。在我的应用程序中,我在 UIImage 上应用了很多图像操作,我想存储每个状态并相应地应用 Undo
我将以下代码用于核心数据单例。下面是我的代码。 (基于 NachoMan 的 blog 。但是代码来自他的要点。 // DataManager.h #import #import extern N
如何在 Swift 中使用 UndoManager(以前的 NSUndoManager)? 这是我尝试复制的 Objective-C 示例: [[undoManager prepareWithInvo
我正在尝试在类似绘画的程序中设置UndoManager,但不幸失败了。我一直在查看的示例程序是文本编辑器 ( Example ),它们调用 JTextComponent 类的 addUndoableE
我尝试使用 undomanager 撤消/重做编辑顶点。 图形对象经过测试。但我不知道该怎么做编辑顶点撤消/重做。 顶点是否可以撤消/重做? 我找了很多例子都没有找到答案。 我是韩国初学者程序员。帮帮
使用 Swift 3.02 (Xcode 8.2) 我引用了答案中描述的撤消解决方案:https://stackoverflow.com/a/31450475/7448394 . 在下面的代码中,我使
我只是试图让用户在我的应用程序中执行的操作撤消。默认情况下,用户所做的任何文本编辑都具有撤消的好处,但以其他方式(通过我的代码)完成的任何操作都没有。 我可以看到文档解释说我需要获取 NSUndoMa
为什么@Environment UndoManager不更新其 canUndo当它的堆栈中有 Action 时的属性?我有一个 View ,它有一个可以使用取消/重做功能的 child ,但由于某种原
我是一名优秀的程序员,十分优秀!