Swing - Get new component under mouseReleased
===

This question probably belies underlying lack of Swing knowledge, but I can't seem to pin down what I'm doing wrong.   Essentially I want to detect mousePressed in one component, and then receive the mouseReleased for whatever component is under the mouse when it is released, rather than the original component.


    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.event.MouseInputAdapter;
    import net.miginfocom.swing.MigLayout;
    
    public class TestMouseListener extends MouseInputAdapter {
    	
    	public void mouseEntered(MouseEvent arg0) {System.out.println("Entered " + arg0.getComponent());}
    	public void mouseExited(MouseEvent arg0) {System.out.println("Exited " + arg0.getComponent());}
    	public void mousePressed(MouseEvent arg0) {System.out.println("Pressed " + arg0.getComponent());}
    	public void mouseReleased(MouseEvent arg0) {System.out.println("Released " + arg0.getComponent());}
    	
    	public static void main(String[] args){
    		JFrame frame = new JFrame();
    		frame.setLayout(new MigLayout());
    		frame.setSize(400, 400);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		TestPanel panel1 = new TestPanel("Panel 1");
    		TestPanel panel2 = new TestPanel("Panel 2");
    		panel1.add(new JLabel("Text1"));
    		panel2.add(new JLabel("Text2"));
    		frame.add(panel1);
    		frame.add(panel2);
    		TestMouseListener listener = new TestMouseListener();
    		panel1.addMouseListener(listener);
    		panel1.addMouseMotionListener(listener);
    		panel2.addMouseListener(listener);
    		panel2.addMouseMotionListener(listener);
    		frame.setVisible(true);
    	}
    }
    class TestPanel extends JPanel {
    	String name;
    	TestPanel(String name){ this.name = name; }
    	public String toString(){ return name; }
    }

So when I mouse over panel 1, click, drag to panel 2, release, I get the following:

    Entered Panel 1
    Pressed Panel 1
    Exited Panel 1
    Entered Panel 2
    Released Panel 1

How do I get the panel I released over?  I was hoping the mouseReleased event would fire for Panel 2 but obviously it does not.