Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JPanel redraw issues

Tags:

java

swing

jpanel

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?

like image 603
Ryan Ahearn Avatar asked Aug 21 '08 19:08

Ryan Ahearn


1 Answers

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

like image 109
Outlaw Programmer Avatar answered Sep 29 '22 13:09

Outlaw Programmer