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

MouseWheelEvents have the wrong mouse position in a child component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta3
    • x86
    • windows_2000


      ###@###.### 2001-08-15

      J2SE Version (please include all output from java -version flag):
        java version "1.4.0-beta_refresh"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b72)
        Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b72, mixed mode)

      Does this problem occur on J2SE 1.3? Yes / No (pick one)
        Not applicable (1.4-specific functionality)

      Operating System Configuration Information (be specific):
        Win2K
        Linux

      Hardware Configuration Information (be specific):
        PIII-800, 256MB of RAM, etc...


      Bug Description:

      MouseWheelEvents have the wrong mouse position encoded into them when the
      event originates in a child component (or deeper below) because the
      coordinate conversion code in Component.java is incorrect.


      Steps to Reproduce (be specific):

      Run the attached MerlinMouseWheelTest.java program
      The results are in button coordinate space but the listener was added to the
      content pane so they should be in content pane coordinate space (and the
      code which translates the coordinates is just plain broken in
      Component.java).

      To confirm this:

      Move the mouse to the upper left corner of each button and rotate the
      wheel.

      Results (Have a look at the y coordinate):

      First button: Mouse coordinates (x,y) = (5, 25)
      Second button: Mouse coordinates (x,y) = (6, 23)
      Third button: Mouse coordinates (x,y) = (5, 24)

      If the coordinates were in content pane coordinate space then the y value
      would have to be bigger for the second and bigger again for the third
      button. This is not the case.

      This bug prevents programmers from just adding the mousewheel listener to a
      top-level component (like the JFrame content pane) and deciding what to do
      with the event based on the coordinates.

      Test program(MerlinMouseWheelTest.java):
      ---------------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      /**
       * Short application to show off a bug in the Merlin mousewheel support:
       *
       * Expected behaviour:
       *
       * All mouse coordinates when the mousewheel is moved are supposed to be in the content pane's
       * coordinate space.
       *
       * Shown behaviour:
       *
       * The coordinates are NOT correct.
       *
       * Steps to reproduce:
       *
       * - Run the application and rotate the mouse wheel while hovering over each of the buttons
       * - Observe that the coordinates are not correct!
       */

      public class MerlinMouseWheelTest
      {
      public static void main(String[] args)
      {
      JFrame f = new JFrame();

      f.getContentPane().setLayout(new GridLayout(3,1));

      f.getContentPane().add(new Button("Button 1"));
      f.getContentPane().add(new Button("Button 2"));
      f.getContentPane().add(new Button("Button 3"));

      f.addMouseWheelListener
      (
      new MouseWheelListener()
      {
      public void mouseWheelMoved(MouseWheelEvent e)
      {
      System.out.println("Mouse coordinates (x,y) = ("+e.getX()+", "+e.getY()+")");
      }
      }
      );
      f.pack();
      f.show();
      }
      }

            bchristi Brent Christian
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: