tags:

views:

34

answers:

1

I have taken a JPanel (say cardsPanel) and have set its layout as CardsLayout. After that I have added 3 cards on it (say card1, card2, and card3) all of JPanel type.

Now I want to get the topmost card of the cardsPanel whenever a user clicks on a button "Show".

So, How can I get the top-most card of the cardsPanel.

+1  A: 

The CardLayout has four methods which might be of use to you.

The Container you pass in is the reference to the parent of your cards 1 to 3. So in the actionPerformed of the 'Show' button just use the appropriate method (first I guess?).

willcodejavaforfood
I think he wants to perform the inverse operation. I think he needs to pull the JPanel off of the CardLayout, which I don't believe is possible directly.
Stefan Kendall
In either case, the questioner can specify a name in `addLayoutComponent()` and use `show()` or `removeLayoutComponent`.
trashgod