错误对话框未被破坏

发布于 2024-07-11 10:24:17 字数 1044 浏览 6 评论 0原文

我正在开发一个项目,该项目使用 JTable 来显示日期列等。 我们需要对用户输入的日期进行验证,因此我实现了格式验证的屏蔽和实际日期验证的解析的组合。 我已经使用日期列的自定义单元格编辑器完成了此操作。

在我的 MaskedCellEditor 中,我有一个 JFormattedTextField。 我设置了日期屏蔽。 然后我添加一个 InputVerifier 以允许实际验证。 我的 InputVerifier 实现 verify() 来检查: 1. textField.isEditValid() 2. DateValidator.ValidDate()。 如果其中一个无效,则 verify 返回 false,并且 InputVerifier 将焦点锁定到文本字段(单元格编辑器),并显示一个小消息对话框,提醒用户日期格式。

错误消息是一个小的、未修饰的、非模态的、不可聚焦的 JDialog,它会在正在编辑的单元格下方弹出。 它会在按键或成功的日期验证后消失。 除了小边缘情况外,它工作得很好。

如果用户选择应用程序顶部的菜单按钮,同时弹出无效编辑对话框,则会切换屏幕,破坏当前屏幕上的所有内容(包括表格)。 但是,由于正在显示对话框并且尚未发生按键/成功编辑,因此该对话框永远不会隐藏。 它在不同屏幕上完全不相关的上下文中仍然可见。 一旦用户关闭了表格的屏幕,用户就无法摆脱该对话框。

我曾讨论过在对话框本身上放置一个计时器和/或鼠标监听器,这会导致它消失,但我觉得我忽略了实际的问题。 该对话框永远不会被处理,我很确定它是因为它仍然设置为可见,并且它阻止垃圾收集器处理它。

我在持有 JTable 的面板上有一个 Cleanup 方法,但我找不到引用对话框(InputVerifier 的一个组件)以摆脱它的好方法。 该对话框与表的父面板相距甚远。 (Panel -> JTable -> CellEditor -> JFormattedTextField -> InputVerifier -> JDialog)

关于如何在表被销毁时强制隐藏对话框的任何想法? 如果您需要更多详细信息,请告诉我。 我不想让你们陷入细节的泥潭,但事情确实有很多。

I am working on a project that is using a JTable to display, among other things, a column of dates. We needed validation for the user input for dates, so I have implemented a combination of masking for format validation and parsing for actual date validation. I have done this using a custom CellEditor for the date column.

Inside my MaskedCellEditor, I have a JFormattedTextField. I setup the masking for dates. Then I add an InputVerifier to allow for actual validation. My InputVerifier implements verify() to check: 1. textField.isEditValid() 2. DateValidator.ValidDate(). If either is invalid, verify returns false and the InputVerifier locks the focus into the text field (the cell editor) and a small message dialog is displayed reminding the user of the date format.

The error message is a small, undecorated, non-modal, non-focusable JDialog that pops up underneath the cell being edited. It disappears on a keypress or a successful date verification. It is working great except for a small edge case.

If the user selects a menu button on the top of the application while an invalid edit has popped up the dialog, it switches screens, destroying everything currently on the screen (including the table). However, since the dialog is being shown and a keypress/successful edit has not occurred, the dialog is never hidden. It remains visible in a completely unrelated context on a different screen. Once the user has switched off the screen with the table, there is no way for the user to get rid of the dialog.

I have debated throwing either a Timer and/or a MouseListener on the dialog itself that would cause it to disappear, but I feel that I am ignoring the actual problem. The dialog is never being disposed of and I am pretty sure its because it is still set to be visible and it is preventing the garbage collector from getting rid of it.

I have a Cleanup method on the panel holding the JTable, but I cannot find a good way to reference the dialog (a component of the InputVerifier) in order to get rid of it. The dialog is pretty far removed from the table's parent panel. (Panel -> JTable -> CellEditor -> JFormattedTextField -> InputVerifier -> JDialog)

Any ideas on how to force the dialog to be hidden when the table is destroyed? If you need more details, let me know. I'm trying not to get you guys bogged down in the details, but there is a lot going on.

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

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

发布评论

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

评论(2

空城之時有危險 2024-07-18 10:24:17

首先想到的是,你能不能不要采用倾听者的方法。 如果您有一个 closeErrorDialog() 类型的方法,该方法在成功验证时被调用,那么您也可以在选择菜单操作时调用它。

作为替代方案,也许您可​​以以某种方式控制从菜单到菜单的转换,并创建一个“清理”方法来关闭任何现有的错误对话框。 这将允许更改菜单时需要执行的任何其他操作在同一位置发生。

只是我脑海中的一些快速想法。 希望它们符合您的意思

As a first thought, can you not go down the listener approach. If you have a closeErrorDialog() type method that gets called when upon successful valdiation, then you can also call it when a menu action is selected.

As an alternative, perhaps you could control the transition from menu to menu in some way, and create a "cleanup" method which will close down any exisiting error dialogs. This would allow for any other actions that need to take place when changing menus, to happen in the same place.

Just a couple of quick ideas of the top of my head. Hope they are along the lines of what you meant

橘味果▽酱 2024-07-18 10:24:17

很多人会因为我这样说而投票反对,但听起来你的对话框应该是模态的,这样用户就不能在不先关闭它的情况下离开它。 或者至少禁用允许人们在显示此对话框时切换离开的菜单。

Many people will vote me down for saying this, but it sounds like your dialog should be modal so that users can't switch away from it without dismissing it first. Or at least disable the menus that allow people to switch away while this dialog is displayed.

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