title: JPanel created on click not appearing
body: <p>The below code is not my actual code but a concise, runnable remake of what I am trying to achieve. I want the <code>JPanel CP</code>, an instance of <code>clickPanel</code>, to appear when the user clicks on the image in <code>JPanel hasAnImage</code>. I can see in the Netbeans console that the is executing because of the Sys.out.print, but nothing appears on the screen. I have tried setting visible to false then true again and <code>revalidate()</code> in the <code>mousePressed</code> event; the image moves to the left, but nothing appears on the screen. The goal is for <code>CP</code> to appear. What am I missing? Hope my question is clear. </p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  import javax.swing.BorderFactory;
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  public class Testo extends JFrame{
  
      public Testo(){ 
  
          BufferedImage image = null;
          try {
              image = ImageIO.read(new File("C:\\Users\\someimage.jpg"));
          } catch (IOException ex) {
              ex.printStackTrace();
          }
  ;
          final JLabel label = new JLabel(new ImageIcon(image));
          JPanel hasAnImage = new JPanel();
          hasAnImage.addMouseListener(new MouseAdapter(){
              @Override //I override only one method for presentation
              public void mousePressed(MouseEvent e) {
                  clickPanel CP = new clickPanel();
                  hasAnImage.add(CP);
                  revalidate();
                  //setVisible(false);
                  //setVisible(true);
              }
          });
          hasAnImage.add(label);
          add(hasAnImage);
          setVisible(true);
      }
  
      public static void main(String[] args) {
  
          Testo frame = new Testo(); 
          frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
          frame.getContentPane().setBackground(Color.WHITE);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
  
      public class clickPanel extends JPanel{
  
          public clickPanel() {
              setPreferredSize(new Dimension(100,60));
              setMaximumSize(new Dimension(100,60));
              setBackground(new Color(1.0f,1.0f,1.0f,0.1f));
              setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.GREEN));
              System.out.println("This is being executed...");
          }
  
          @Override
          protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.setFont(new Font("Arial", Font.PLAIN, 12));
              g.setColor(Color.GREEN);
              g.drawString("CLICK", 2, 2);
          }
      } 
  }
  </code></pre>