Card Layout


You can think of a Card Layout as a deck of cards. During run time, only one component ("the top card") is visible at a time and each component ("card") is the same size. In design time in the Form Editor, the Card Layout is displayed as a JTabbedPane to make it easier to design the form. This enables you to switch between cards by clicking on their tabs when you are designing the form.

In the property sheet for the CardLayout node, you can set the Current Card property to card1, card2, and so on. In code, the methods show, next, previous, first, and last can be used to select cards. For example, the following code selects the next card in panel1 when button1 is clicked:

 private void button1ActionPerformed(java.awt.event.ActionEvent 
evt) {
   // Add your handling code here:
   CardLayout cards = (CardLayout)panel1.getLayout();
   cards.next(panel1);
 }

See the JTabbedPane component if you want to design a visual form that has tabbed panes in run time.


Contents Prev Next Index