Detect which card is visible with a CardLayout

From CodeCodex

Implementations[edit]

Java[edit]

Component getComponentShowing(Container c) {
   Component[] comps = c.getComponents();
   int i = 0;
   while(i < comps.length && !comps[i].isVisible())
      ++i;
   return (i == comps.length) ? null : comps[i];
   }