tags:

views:

1973

answers:

1

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?

+6  A: 

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().

Outlaw Programmer
A background thread was exactly the problem. Thanks.
Ryan Ahearn