Saturday, February 18, 2012

Using Netbeans to Create a CardLayout V2

In the previous post, I went to great length to write a tutorial on how to use CardLayout in Netbeans. when it came to choosing which panels to use, I just chose the next panel that is within the bottomPanel.


  private void clickButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
        cl.next(bottomPanel);
    }

If you want to choose which panel would be shown, all you have to do is just change the cl.next(bottomPanel) to 
cl.show(bottomPanel,"card4");

so the previous method will become: 

  private void clickButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
       cl.show(bottomPanel,"card4");
    }

"card4" is the name of the panel that is red for me. It might be different for you but essentially you have to put the layout name of the panel you want to show. Note that the layout name of the panel might be different from the name of the panel that you set it to. The layout name of the  panel will be under the properties tab on the right hand of the screen.




No comments:

Post a Comment