JComboBox not displaying correctly.

Hi,

Quick question if you don't mind?!

I am writing an application that will (hopefully) automate User Creation, File Sharing and Security Settings across our Windows 2003 domain, but have run into an annoying issue with one of my GUI's in that I can't get a JComboBox to display correctly.

I have a main class that extends JFrame and all my other classes extend JPanel. Then when certain events are triggered I basically remove the current panel, load another and repaint. e.g.

this.getContentPane().remove( panel_object1 );

this.getContentPane().add( panel_object2 );

repaint();

This has been working fine, infact I poached alot of the code from an application I wrote some years back that manages Memory Resident Programs in Windows XP; however I have reached a dead end with a JComboBox.

The box appears not to have been fully loaded, as only its outline exists. If you click the screen where it should be the drop down list appears. The functionality is fine apart from the box, the down arrow and the initial option is not visible.

To further confuse me, I rearranged the order of the panels so it was the one loaded by default when the application is loaded and it appears correctly, and switching between screens does not cause any problems.

However, if I don't load the Panel it resides on first the problem continues, I even tried loading it and then forcing a call to the exit method to reload the main screen as part of the main constructor but this did not solve the problem.

This must be an issue with getting the GUI to reload or refresh correctly, but I can't seem to find anything relevant to my case on any of the forums. I could of course change tact and create a TabbedPane, but I would much rather get to the bottom of this if someone is able to help.

Thanks in advance, and if you need some code, or if I have been to vague please let me know,

Coffee_Junkie

[1969 byte] By [Coffee_Junkiea] at [2007-11-27 7:43:14]
# 1

You might need to revalidate() the panel as well as repainting it. But a better solution would probably be to use a single panel with a cardlayout. That way you could switch between the different panels easily. Just add the new panel to the container, and tell it's layout manager to show the new panel. If you have a finite number of panels, just add them all at the beginning and switch between them.

hunter9000a at 2007-7-12 19:24:02 > top of Java-index,Java Essentials,New To Java...
# 2

Fantastic! revalidate() not only solved the JComboBox problem but a similar problem I was having with a couple of JScrollPanes which I had overcome with a rather clunky method to add a blank space to each.

Anyway, thanks again I had not come across either of your suggestions before, and although I cannot guarantee to recode my app to include a cardlayout I will certainly read up on it, and use it in the future.

Thanks again, for the all the help,

Kris

Coffee_Junkiea at 2007-7-12 19:24:02 > top of Java-index,Java Essentials,New To Java...