Search code examples
javaswingcardlayout

Get Reference to Currently Displayed Card


Let’s say I have a JPanel named cards and it has a layout type of CardLayout. Each card in the layout is also of classJPanel. How do I get a reference to the JPanel that’s currently being displayed in the layout?

Thanks.


Solution

  • How do I get a reference to the JPanel that’s currently being displayed in the layout?

    There is nothing in the API that allows you to do this, that I'm aware of. So,I extended the CardLayout to provide this information.

    Check out Card Layout Focus for my implementation that allows you to get this information among other things.