JDialog:如何禁用我的Modal对话框的ESC键? [英] JDialog: How to disable the ESC key of my Modal dialog?

查看:368
本文介绍了JDialog:如何禁用我的Modal对话框的ESC键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以有一个框架(主应用程序)。从这里,我打开一个Modal JDialog并启动一个后台线程,同时在一个表中显示进度(日志条目)。这个过程是至关重要的,应该可以停止/隐藏/关闭,因此为什么对话框的关闭按钮被停用,直到一切都完成。但是,用户可以在任何时间点击ESC键,并调用onCanceled(),从而调用this.dispose()。

So there's a frame (main app). From here, I open a Modal JDialog and start a background thread working whilst displaying progress (log entries) in a table. This process is critical and should not be stoppable/hideable/closeable, thus why the dialog's close button is de-activated until everything's finished. However, the user can at any time tap the ESC key and my onCanceled() is called, thus calling this.dispose().

编辑:
我继承了这个项目,并监督继承的兔子洞的深度,从而监督ESC的处理,其次是e.consume(),这就是为什么我的解决方案不工作!

I inherited this project and oversaw how deep the rabbit hole of inheritance went, thus overseeing handling of ESC already, followed by e.consume() which is why my solutions weren't working!

推荐答案


然而,用户可以随时点击ESC键,我的onCanceled()被调用

However, the user can at any time tap the ESC key and my onCanceled() is called

这听起来像添加到APP的自定义代码,因为默认情况下,大多数LAF都没有实现Escape键。所以我会删除自定义代码。

This sounds like custom code added to the APP since most LAF's don't implement the Escape key by default. So I would remove the custom code.

但是,如果您的LAF的默认行为,那么截取Escape键的正确方法是使用密钥绑定。本教程将显示如何覆盖/删除绑定。

However,if this default behaviour for your LAF then the proper way to intercept the Escape key is to use Key Bindings. The tutorial shows how to override/remove a binding.

这篇关于JDialog:如何禁用我的Modal对话框的ESC键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆