javaswingcardlayout

How to Count Number of Cards in a CardLayout


I have a JPanel which uses a CardLayout to have a number of pages, and to make a progress bar that fills up as pages are defined, I would like to count the number of cards added to my CardLayout. Is there a way of counting cards programatically, or will I have to track the number of pages with a variable?


Solution

  • Since the cards are the only components that the JPanel holds, then indeed getComponentCount() returns the number of pages.