Mac OS X 10.6 Update 2 (1.6.0_20) Java 中 JFormattedTextField 删除错误的解决方法

发布于 2024-09-04 05:08:49 字数 374 浏览 11 评论 0原文

显然,Mac OS X 的最新 Java 更新中引入了一个错误,导致 JFormattedTextFields 中的删除操作执行两次。 请参阅http://lists.apple.com/archives/java -dev/2010/May/msg00092.html

当按下删除键时,DefaultEditorKit.deletePrevCharAction 会被调用两次。

有解决方法的建议吗?

我正在考虑用修补版本替换文本字段的删除操作,以某种方式过滤掉这些重复的调用。

There is apparently a bug introduced in the latest Java update for Mac OS X, which causes deletes in JFormattedTextFields to be performed twice.
See http://lists.apple.com/archives/java-dev/2010/May/msg00092.html

The DefaultEditorKit.deletePrevCharAction is invoked twice when the delete key is pressed.

Are there any suggestions for a workaround?

I'm thinking of replacing the delete action for my text fields with a patched version that somehow filters out these duplicate invocations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必你懂 2024-09-11 05:08:49

我的解决方法似乎效果很好:

public class PatchedTextField extends JFormattedTextField {

    public PatchedTextField() {
        super();

        final Action originalDeleteAction =
            getActionMap().get(DefaultEditorKit.deletePrevCharAction);

        getActionMap().put(DefaultEditorKit.deletePrevCharAction,
            new AbstractAction() {
                ActionEvent previousEvent;

                public void actionPerformed(ActionEvent e) {
                // Filter out events that happen within 1 millisecond from each other
                if (previousEvent == null || e.getWhen() - previousEvent.getWhen() > 1) {
                    originalDeleteAction.actionPerformed(e);
                }
                previousEvent = e;
            }
        });
    }
}

到目前为止我发现的唯一缺点是每毫秒不能删除多个字符。

My workaround, that seems to be working quite well:

public class PatchedTextField extends JFormattedTextField {

    public PatchedTextField() {
        super();

        final Action originalDeleteAction =
            getActionMap().get(DefaultEditorKit.deletePrevCharAction);

        getActionMap().put(DefaultEditorKit.deletePrevCharAction,
            new AbstractAction() {
                ActionEvent previousEvent;

                public void actionPerformed(ActionEvent e) {
                // Filter out events that happen within 1 millisecond from each other
                if (previousEvent == null || e.getWhen() - previousEvent.getWhen() > 1) {
                    originalDeleteAction.actionPerformed(e);
                }
                previousEvent = e;
            }
        });
    }
}

The only downside that I have found so far is that you cannot delete more than one character per millisecond.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文