title: How to show specific scrollpane in a CardLayout?
body: <p>I have list of <code>JPanel</code> components. I want to open corresponding panel based on clicking a button. While clicking button, I pass the panel name.  But in my case panel have more components, so I am adding each panel to <code>JScrollPane</code> and adding these scroll panes to <code>CardLayout</code>. </p>
  
  <p>Based on this <a href="https://stackoverflow.com/a/5655843/230513">example</a>, here is the code for adding panel to card layout:</p>
  
  <pre><code>final JPanel  cards=new JPanel(new CardLayout());
  cards.setPreferredSize(new Dimension(600, 550));
  for (JPanel p:panels) {
      JScrollPane scrollPanel=new JScrollPane(p);
      scrollPanel.setName(p.getName());
      scrollPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      scrollPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      cards.add(scrollPanel);
  }
  CardLayout cardLayout=(CardLayout) cards.getLayout();   
  cardLayout.show(cards, "name");
  
  control.add(new JButton(new AbstractAction("\u22b2Prev") {
  
      @Override
      public void actionPerformed(ActionEvent e) {
          CardLayout cl = (CardLayout) cards.getLayout();
          cl.previous(cards);
      }
  }));
  
  control.add(new JButton(new AbstractAction("Next\u22b3") {
  
      @Override
      public void actionPerformed(ActionEvent e) {
          CardLayout cl = (CardLayout) cards.getLayout();
          cl.next(cards);
      }
  }));
  </code></pre>
  
  <p>But clicking button shows first panel in the card layout.</p>
  
  <p>How to solve this problem? Can I use scroll pane name instead of panel name in show method?</p>