The CardLayout
simply provides cards, it is up to you to determine which card should be visible. It provides some ordered-list style API methods for convenience (presumably because the designers decided that that was one of the more common use cases) but you don't have to use them.
Implement flow control in your buttons (or in whatever code you're using to determine the behavior here) and just use CardLayout.show()
to show the appropriate card. You don't have to use first()
, last()
, previous()
, and next()
if you don't want to.