how-to

Window (swing) applications

How to work with a CardLayout (notebook style) ?

For this example you must use:

import java.awt.CardLayout;

STEP 1 - Prepare frame/dialog/container

At first set layout in (here) a frame to the java.awt.CardLayout. Then add two javax.swing.JPanel and some other objects.

STEP 2 - Remame panels

Set CardName for every panels (if you want work with it later):

STEP 3 - Page channing

For page changing in java.awt.CardLayout use this code:

/* -- get layout for right(!) container */
CardLayout card = (CardLayout) getContentPane().getLayout();

/* -- activating "card2" panel */
card.show( getContentPane(), "card2" );
or, for example:
/* -- get layout for right(!) container */
CardLayout card = (CardLayout) getContentPane().getLayout();

/* -- activating previous panel */
card.previous( getContentPane() );