title: select JPanel parent at the back
body: <p>Below is SSCCE to describe my problem.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import javax.swing.JPanel;
  
  public class APanel extends JPanel{
  
  public APanel() {
  
      this.setVisible(true);
      this.setBackground(Color.red);
      this.addMouseListener(new MouseListener() {
  
          public void mouseClicked(MouseEvent e) {
              if(e.getClickCount()==2)
              {
  
              }
              System.out.println("Child panel clicked!");
          }
          public void mousePressed(MouseEvent e) { }
          public void mouseReleased(MouseEvent e) {}
          public void mouseEntered(MouseEvent e) { }
          public void mouseExited(MouseEvent e) {}
      });
    }
  }
  
  
      import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class PPanel extends JPanel{
      private APanel panel1;
      private APanel panel2;
      private APanel panel3;
      public PPanel() {
          this.setLayout(new GridLayout(0,1));
          panel1 = new APanel();
          panel2 = new APanel();
          panel2.setBackground(Color.yellow);
          panel3 = new APanel();
          panel3.setBackground(Color.green);
          this.add(panel1);
          this.add(panel2);
          this.add(panel3);
          this.setBackground(Color.blue);
           this.addMouseListener(new MouseListener() {
              public void mouseClicked(MouseEvent e) {
                  System.out.println("Parent panel clicked!");
              }
              public void mousePressed(MouseEvent e) { }
              public void mouseReleased(MouseEvent e) {}
              public void mouseEntered(MouseEvent e) { }
              public void mouseExited(MouseEvent e) {}
          });
      }
  
      public static void main(String[] args) {
          JFrame frame = new JFrame();
          PPanel panel = new PPanel();
          frame.add(panel);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(new Dimension(350, 300));
          frame.setTitle("Demo");
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>How can I do the following: </p>
  
  <ul>
  <li>If e.getClickCount()==1 then the parent MouseListener will active and it will print "parent panel clicked!".</li>
  <li><p>If e.getClickCount()==2 then the children MouseListner will active and print out "child panel clicked!".</p>
  
  <p>Edit1: Closer to the proposed solution.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  public class APanel extends JPanel {
  
  private static final long serialVersionUID = 1L;
  private Point pt;
  
  public APanel() {
      timer.setRepeats(false);
      addMouseListener(new MouseAdapter() {
  
          @Override
          public void mouseClicked(MouseEvent e) {
              if (timer.isRunning() &amp;&amp; !e.isConsumed() &amp;&amp; e.getClickCount() &gt; 1) {
                  System.out.println("double from child");
                  pt = null;
                  timer.stop();
              } else {
                  pt = e.getPoint();
                  Component component = (Component)e.getSource();
                  component.getParent().dispatchEvent(e);
                  timer.restart();
              }
          }
      });
      setBackground(Color.red);
      setVisible(true);
  }
  
  private Timer timer = new Timer(200, new ActionListener() {
  
      @Override
      public void actionPerformed(ActionEvent e) {
          //System.out.println("single from child");
      }
  });
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>In case, a mouseEvent needs to pass through multiplevel of containers, this <a href="https://stackoverflow.com/questions/7211106/swing-dispatch-event-to-multiple-level-of-containers">link</a> might be of interest.</p>