This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi. I'm very new to developing GUIs and I need to switch between two sets of controls. I have a set of radio buttons to switch between two modes. Each mode has its own set of controls that should appear when the corresponding radio button is selected.
To do this, I added a Panel to my GUI and then added another Panel containing the controls for one mode (the subcontrols) to the first panel. Whenever the mode switches, I plan to remove the current child panel and replace it with a new panel containing the correct subcontrols for the new mode.
I'm using these parent and child Panels so that I can choose where the subcontrols go in the GUI. I place the parent Panel in my GUI and then I can call add() and remove() on it as needed. The subcontrols always stay in the same screen location.
What I find is that the subcontrols are visible when the GUI is first rendered. However, when I switch the radio buttons, the first set of subcontrols are removed and the new set of subcontrols are not visible. I know that the parent Panel remains the same size but the child Panel has a size of 0,0.
Here are the methods I'm using to switch between the control sets. When the GUI is initially created, I call initializeSpecializedControls(). Then when one or the other radio button is selected, it calls either showUnitsControls() or showBuildingControls(). I know the last two methods are being called when I select the radio buttons. I'm surprised that calling them doesn't create a full-sized and visible set of controls because the only difference between them and the initialize method is that the show*Controls() methods also remove the existing Panel.
Is there a simpler way to switch some of the controls in a GUI depending on a mode selection? I've tried setting the size of the child Panel explicitly and I can make it appear on the screen. However, it's controls are not present, only the background color. The UnitControls() and BuildingControl() contructors create the controls the first time, why would they behave differently later on?
I'm using JDK 1.6. I apologize for some vagueness here. Any thoughts will be appreciated.