How can I determine which card is curently being displayed in a CardLayout?
Created May 4, 2012
Scott Stanchfield The displayed component will be the only one in the container that is visible.
You can walk through the components in the container and check which one is visible.
For example, to determine if you're on the first or last component (perhaps to disable "previous" and "next" buttons) you could do something like the following (assuming p is the panel with the CardLayout)
boolean firstShowing = p.getComponent(0).isVisible(); boolean lastShowing = p.getComponent(p.getComponentCount()-1).isVisible();