title: unable to identify current visible card in CardLayout
body: <p>i have a JPanel like:</p>
  
  <pre><code>public class CardLayoutPanel extends JPanel {
  String[] option = {"login", "register"}    
  public CardLayoutPanel() {
      super();
      combo_box = new JComboBox(option);
      login_panel = new LoginForm();
      register_panel = new RegisterForm();
  
      layout = new CardLayout();
      this.setLayout(new BorderLayout());
      panel = new JPanel();
      panel.setLayout(layout);
  
      this.add(combo_box, BorderLayout.NORTH);
      this.add(panel, BorderLayout.SOUTH);
  
      panel.add(login_panel, "login");
      panel.add(register_panel, "register");
  
      layout.show(panel, "login");
      combo_box.addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent e) {
              JComboBox source = (JComboBox) e.getSource();
  
              if(source.getSelectedItem().equals("login")) {
                  layout.show(panel, "login");
              }else if(source.getSelectedItem().equals("register")) {
                  layout.show(panel, "register");
              }
          }
      });
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and i call from my main calss inside a JOptionPane</p>
  
  <pre><code>CardLayoutPanel card_panel = new CardLayoutPanel();
  
      int res = JOptionPane.showConfirmDialog(null, card_panel, "Login/Registrati",JOptionPane.OK_CANCEL_OPTION);
  </code></pre>
  
  <p>Now, if i try to obtain the current visible card like</p>
  
  <pre><code>if(res == JOptionPane.OK_OPTION) {
          for(Component comp : card_panel.getComponents()) {
              if(comp.isVisible() == true) {
                  JPanel current_panel = (JPanel) comp;
  
                  System.out.println(current_panel.getName());
              }
          }
      }else if(res == JOptionPane.CANCEL_OPTION) {
          System.exit(-1);
      }
  </code></pre>
  
  <p>i obtain the sequent error:  </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ClassCastException: javax.swing.JComboBox cannot be cast to javax.swing.JPanel</p>
  </blockquote>
  
  <p>on this row inside for each statement:</p>
  
  <pre><code>JPanel current_panel = (JPanel) comp;
  </code></pre>
  
  <p>how can i fix it?</p>