空白弹出菜单和组合框

发布于 2024-11-02 16:55:42 字数 451 浏览 0 评论 0原文

我发现 JPopupMenu 和 JComboBox 存在一个非常奇怪的问题。当应用程序负载较重时,有时我们的弹出菜单会以正确的大小和位置出现,但只是空白的灰色框。

我们认为相关的另一个问题是,有时,我们看到标准 JComboBox 看起来好像其中没有项目(即,它们不会下拉)。当应用程序未加载时,我们已经看到了此问题。他们不会进行数据库调用或类似的操作来填充组合框项目 - 他们使用硬编码项目。

我已将弹出菜单创建放在 SwingUtils.invokelater 调用中,这有所帮助,但并没有使问题完全消失。我不知道我会做什么来改变组合框的行为。如果我们再次右键单击,上下文菜单将重新出现 - 完全填充。为了让组合框再次正常工作,我们只需关闭包含它们的对话框,然后重新打开它即可。

我们在标准桌面应用程序中使用 Java 1.6.17。是否存在我不知道的错误,或者有其他可以解决该问题的方法,或者至少可以帮助我们了解可能发生的其他情况?

I'm seeing a really strange issue with JPopupMenu's and JComboBox's. When the application is under heavy load, there are times when our popup menus appear with the right size and position, but just as blank, grey boxes.

The other issue we think is related is that sometimes, we see stanards JComboBox's appear as though they have no items in them (i.e., they don't pull down). We've seen this issue when the application is not under load. They're not making database calls, or anything like that to populate the combo box items - they use hard-coded items.

I've put the popup menu creation in a SwingUtils.invokelater call, and that helped, but did not make the problem completely go away. I don't know what I would do to change the combo box's behavior. If we just right-click again, the context menu will reappear - fully populated. To get the combo boxes working right again, we just close the dialog that contains them, and then just open it back up.

We're using Java 1.6.17 in a standard desktop app. Is there a bug I don't know about, or something else that would solve it, or at least help us know what else might be going on?

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

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

发布评论

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

评论(1

一影成城 2024-11-09 16:55:42

所有 GUI 组件都应该构建在“事件调度线程”,并且对另一个线程拥有的任何数据的访问必须正确同步。 < 下有一个很好的摘要em>内存一致性属性

附录:@Boro 提出了与此问题相关的两个令人信服的观点。

我从未遇到过此类问题,我希望看到一个。

该问题的间歇性仅表明同步不正确,但相反的证据是困难。受影响的系统可能太大而无法通过检查进行纠正;遗憾的是, sscce 是人为的,而且显然是不正确的。

代码中可能还有其他内容,因为 invokeLater() 没有完全帮助。

一种常见的场景是延迟构造的 ListModel,可能是在另一个线程上构造的。一种方法是记录 EventQueue 并查找异常情况,如此处的建议。

All GUI components should be constructed "on the event dispatch thread," and access to any data owned by another thread must be correctly synchronized. There's a nice summary under Memory Consistency Properties.

Addendum: @Boro raises two compelling points related to this problem.

I have never experienced this kind of issue, and I would like to see one.

The intermittent nature of the problem only suggests incorrect synchronization, but proof to the contrary is difficult. The affected system is likely too large to correct by inspection; sadly, an sscce would be contrived and obviously incorrect.

There might be something else in the code as well, since invokeLater() didn't help completely.

One common scenario is a ListModel that is constructed lazily, perhaps on another thread. One approach is to log the EventQueue and look for anomalies, as suggested here.

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