简体   繁体   English

Java JPanel重绘问题

[英]Java JPanel redraw issues

I have a Java swing application with a panel that contains three JComboBoxe s that do not draw properly. 我有一个Java swing应用程序,其面板包含三个无法正确绘制的JComboBoxe
The combox boxes just show up as the down arrow on the right side, but without the label of the currently selected value. combox框只显示为右侧的向下箭头,但没有当前所选值的标签。
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. 我所有的谷歌搜索都指向在JPanel上调用revalidate()来解决这个问题,但这对我没有用。
Calling updateUI() on the JPanel has changed it from always displaying incorrectly to displaying incorrectly half of the time. JPanel上调用updateUI()已将其从始终显示错误更改为显示错误的一半时间。

Has anyone else seen this and found a different way to force a redraw of the combo boxes? 有没有其他人看过这个并找到一种不同的方法来强制重绘组合框?

Can you give us some more information on how you add the combo boxes to the JPanel? 您能否向我们提供有关如何将组合框添加到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. 这在Swing中是很常见的事情所以我怀疑这是一个JVM问题,但我想任何事都有可能。

Specifically, I would double check to make sure you're not accessing the GUI from any background threads. 具体来说,我会仔细检查以确保您没有从任何后台线程访问GUI。 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. 在这种情况下,也许您正在从数据库或其他东西中读取选项并从后台线程更新JComboBox,这在Swing中是一个很大的禁忌。 See SwingUtils.invokeLater(). 请参阅SwingUtils.invokeLater()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM