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.

The 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 the tabbed pane.

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

 MethodsDescriptionpublic  first(Container parent)Shows the first card of the parent containerpublic next(Container parent)Shows the next card of the parent container. If the current visible card is the last one, it will flip 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 flip 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 the user clicks each control button, the card will flip accordingly.

Here are screenshots of the CardLayout demo application: