Java Swing CardLayout

Java Swing CardLayout manages components in a stack where only the top one is visible at any time. Normally all components with the same display time are placed in a JPanel when using with CardLayout.

User can choose which components to display by making choices through UI such as selecting from an item from combobox or choosing a tab from tabbed pane.

These are important methods you need to know when working with the CardLayout:

 MethodsDescription
public  first(Container parent)Shows  the first card of the parent container
public next(Container parent)Shows the next card of the parent containerIf the current visible card is the last one, it will flips to the first one.
public previous(Container parent)Shows to the previous card of the parent container. If the current visible card is the first one, it will flips to the last one.
public  last(Container parent)Show the last card of the parent container.
public  show(Container parent,String name)Show the card with a given name.

In the demo application, we will show you how first, next, previous and last function work in CardLayout. When user clicks each control button, the card will flip accordingly.

Here are screenshots of the CardLayout demo application:

Java Swing CardLayout

Java Swing CardLayout

Java Swing CardLayout