Java JPanel 重绘问题

发布于 2024-07-04 09:53:13 字数 362 浏览 7 评论 0原文

我有一个 Java swing 应用程序,其面板包含三个无法正确绘制的 JComboBoxe
组合框仅显示为右侧的向下箭头,但没有当前所选值的标签。
如果窗口的大小调整得更大或更小,即使是一个像素,这些框也会正确地重新绘制。

我所有的谷歌搜索都指向在 JPanel 上调用 revalidate() 来解决这个问题,但这对我来说不起作用。
JPanel 上调用 updateUI() 已将其从始终显示不正确更改为一半时间显示不正确。

有没有其他人看到过这一点并找到了强制重绘组合框的不同方法?

I have a Java swing application with a panel that contains three JComboBoxes that do not draw properly.
The combox boxes just show up as the down arrow on the right side, but without the label of the currently selected value.
The boxes will redraw correctly if the window is resized either bigger or smaller by even one pixel.

All of my googling has pointed to calling revalidate() on the JPanel to fix this, but that hasn't worked for me.
Calling updateUI() on the JPanel has changed it from always displaying incorrectly to displaying incorrectly half of the time.

Has anyone else seen this and found a different way to force a redraw of the combo boxes?

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

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

发布评论

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

评论(1

飞烟轻若梦 2024-07-11 09:53:13

您能否向我们提供有关如何将组合框添加到 JPanel 的更多信息? 这是 Swing 中很常见的事情,所以我怀疑这是 JVM 问题,但我想一切皆有可能。

具体来说,我会仔细检查以确保您没有从任何后台线程访问 GUI。 在这种情况下,也许您正在从数据库或其他东西读取选择,并从后台线程更新 JComboBox,这在 Swing 中是一个很大的禁忌。 请参阅 SwingUtils.invokeLater()。

Can you give us some more information on how you add the combo boxes to the JPanel? This is a pretty common thing to do in Swing so I doubt that it's a JVM issue but I guess anything is possible.

Specifically, I would double check to make sure you're not accessing the GUI from any background threads. In this case, maybe you're reading the choices from a DB or something and updating the JComboBox from a background thread, which is a big no-no in Swing. See SwingUtils.invokeLater().

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