• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Switching between panels in a GUI

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks for your help.
Posts: 3213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you should use a CardLayout.
Peter Desjardins
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's just what I needed. I was trying to roll my own, badly.


This tiny ad will self destruct in five seconds.
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic