title: Netbeans: Cannot add custom JPanel in Swing Editor
body: <p>I'm having an issue with adding a custom JPanel to a JFrame in the Netbeans Swing Editor.</p>
  
  <p>To rule out other issues, I made a brand new JFrame, and tried to drag my JPanel in (the JPanel is even in the same package). It popped up an error message:</p>
  
  <blockquote>
    <p>Warning: Cannot Load component Class GUI.(nameofpanel) from project
    ...(path)... The class could not be found. Note the class must be
    compiled and must be part of the sources or dependencies of the
    project where the target GUI form belongs to.</p>
  </blockquote>
  
  <p>I've successfully added JPanels to frames before using this method, but now it is preventing me from doing so. I get the same error in versions 7.1 and 7.3 of Netbeans.</p>
  
  <p>I thought I might need to build the JPanel class file, but the option to do so is grayed out. I even tried a clean and build to no effect.</p>
  
  <p>Here is my JFrame:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package gui;
  
  /**
   *
   * @author chris
   */
  public class MainFrame extends javax.swing.JFrame {
  
      /**
       * Creates new form MainFrame
       */
      public MainFrame() {
          initComponents();
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 400, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 300, Short.MAX_VALUE)
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if ("Nimbus".equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //&lt;/editor-fold&gt;
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new MainFrame().setVisible(true);
              }
          });
      }
      // Variables declaration - do not modify                     
      // End of variables declaration                   
  }
  </code></pre>
  
  <p>And my JPanel:</p>
  
  <pre><code>package GUI;
  
  
  import java.awt.Image;
  import java.io.*;
  import javax.imageio.*;
  import javax.swing.*;
  
  /*
   * Represents one card graphically /**
   *
   * @author Student-HSLH133
   */
  public class CardPanel extends javax.swing.JPanel {
  
      private Image cardImage;
  
      /**
       * Creates new form CardPanel
       */
      public CardPanel() {
          initComponents();
          //Set to face down card initially
          //Hey look, some Lisp code, jk
          try {
              cardLabel.setIcon(imageToIcon(ImageIO.read(new File("images/gbCard52.gif"))));
          }
          catch (Exception e){
              System.out.println("Failed to load the image.");
              System.exit(-1);
          }
      }
  
      public void setCard(Image img) {
          cardLabel.setIcon(imageToIcon(img));
          repaint();
      }
  
  // --------------   end of load_picture ---------------------------
      private ImageIcon imageToIcon(Image img) {
          return new ImageIcon(img);
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          cardLabel = new javax.swing.JLabel();
  
          setMaximumSize(new java.awt.Dimension(72, 102));
          setMinimumSize(new java.awt.Dimension(72, 102));
          setPreferredSize(new java.awt.Dimension(72, 102));
          setLayout(new java.awt.BorderLayout());
  
          cardLabel.setMaximumSize(new java.awt.Dimension(72, 102));
          cardLabel.setMinimumSize(new java.awt.Dimension(72, 102));
          cardLabel.setPreferredSize(new java.awt.Dimension(72, 102));
          add(cardLabel, java.awt.BorderLayout.CENTER);
          cardLabel.getAccessibleContext().setAccessibleName("card");
      }// &lt;/editor-fold&gt;                        
      // Variables declaration - do not modify                     
      private javax.swing.JLabel cardLabel;
      // End of variables declaration                   
  }
  </code></pre>
  
  <p>I am totally lost. What is going on?</p>
  
  <p>Edit: I somehow got it to compile the JPanel, but I still get the same error. Thinking it might be something with the JPanel itself, I made a new custom JPanel, compiled it, and tried to add it, and it worked.</p>
  
  <p>Edit 2: I've tried commenting out the custom stuff I've done in the JPanel class, to no avail.</p>