I am trying to make a gui in which I import and combine 4 seperate classes JPanel classes that I made into one interface. But I am running into an obstacle that I am uncertain about.

Here is the situation:
1. I have container using a BoxLayout that has 2 panels one stacked on the other.
2. In the top panel I put the imported panel class that is needed for every transaction. This imported panel has a combobox
3. the bottom panel uses CardLayout and I want its contents (one of 3 other imported panel classes) to be governed by the status of the combobox in the top panel.

Is this possible? if so could someone explain how I would go about it?


Yes, it is possible. It is actually pretty easy. Before you get into it though, I'd recommend that if you have different sized panels, you do not use cardlayout, as I tried this, and it is very difficult to resize them.


Use this link to learn how to do it. You'll need to use the show() method that you see there to switch panels based on what is in the combobox. The code to do that will be in the combobox's actionPerformed method. Ask me if you have any other questions after you read the tutorial. It is a fairly simple tutorial.

Hello and thanks for the response. Yes I have seen that tutorial but my problem is slightly different as the panels are not defined in the same class. All of the children panels of the main container are imported classes that I created separately.

What I don't understand is how to make the combobox from one imported child panel propagate its changed state up to the main container so that the main container's itemStateChanged method can be used to change which card is displayed.


This article has been dead for over six months. Start a new discussion instead.