取消 JComboBox 操作事件
我正在编写一个 gui 程序,并且有一个用于打开文件的 Jbutton 的 AbstractAction。在 JComboBox 中,我有一个已打开的文件列表。 JComboBox 的 AbstractAction 将更改回任何已打开的文件。当我更新 JComboBox 的列表时,该操作会触发。
因此,当我实际打开文件时,JComboBox 操作会触发,而当我使用 JComboBox 时,操作会触发一次,然后在更新时触发第二次。
有没有办法在更新 JComboBox 列表时停止该事件?
提前致谢
I'm writing a gui program and have an AbstractAction for a Jbutton that opens a file. In a JComboBox I have a list of the files that have been opened. The AbstractAction for the JComboBox will change back to any of the files that have been opened. When I update the list for a JComboBox though the action fires.
So when I actually open a file the JComboBox action fires, and when I use the JComboBox the action fires once, then a second time when updating.
Is there a way i can stop the event when just updating the JComboBox list?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案在于设计,特别是关注点的分离:不要考虑具有两个操作的视图,而是考虑多个视图更改单个数据的状态。
在伪代码中,类似于:
The answer is in the design, particularly in separation of concers: don't think view-with-two-actions, instead think many-views-change-state-of-single-data.
In pseudo-code something like: