Ryan Ahearn Ryan Ahearn - 1 year ago 179
Java Question

Java JPanel redraw issues

I have a Java swing application with a panel that contains three

s 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
on the
to fix this, but that hasn't worked for me.

on the
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download