Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6255232

MouseListener.mouseReleased() is not invoked on a component where mouse button released

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      javadoc specification for MouseListener.mouseReleased() method tells:
      Invoked when a mouse button has been released on a component.
      But in fact mouseReleased callback method is invoked on the component where the mouse button was pressed. You can reproduce it running following test program:

      ===
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import java.awt.*;

      public class Test extends Frame {
          public Test() throws HeadlessException {
              setLayout(new FlowLayout());
              add(new Pane());
              add(new Pane());

              setSize(200, 200);
              setVisible(true);
          }

          public static void main(String[] args) {
              new Test();
          }

          public static class Pane extends Panel {
              private static int i = 0;

              private String name;

              public Pane() {
                  name = "Panel " + ++i;
                  setBackground(Color.blue);
                  setPreferredSize(new Dimension(20, 20));

                  addMouseListener(new MouseAdapter() {
                      public void mousePressed(MouseEvent e) {
                          System.out.println("pressed: " + name);
                      }

                      public void mouseReleased(MouseEvent e) {
                          System.out.println("released: " + name);
                      }
                  });
              }
          }
      }
      ===

      Launch the program and move the mouse on first blue panel (left), press first (left by default) mouse button,
      drag the mouse on second blue panel (right) and release mouse button. You sees on the console:
      pressed: Panel 1
      released: Panel 1

      But according to the spec it should be:
      pressed: Panel 1
      released: Panel 2


      ###@###.### 2005-04-14 12:00:19 GMT

        Attachments

          Activity

            People

            • Assignee:
              dav Andrei Dmitriev (Inactive)
              Reporter:
              ydanilev Yury Danilevich (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: