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

MouseWheelEvents propagated to too many listeners

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      linux_sun, windows_nt, windows_2000, windows_xp

      Description

      I'm not sure if this is even a bug, but it is behavior that differs from Swing.

      When MouseWheelListeners are added to several Components of a containment hierarchy, MouseWheelEvents are delivered to listeners all the way up the hierarchy. This differes from Swing, wherein only the top-most listener receives the event. Try the following test case:

      // Test for problem 6 of 4475240

      import java.awt.*;
      import java.awt.event.*;

      public class AWTTest6 implements MouseWheelListener {
          public AWTTest6() {}
          public static void main(String[] args) {
              Frame f = new Frame();
              Panel pnl = new Panel();
              Button btn = new Button("Button");

              pnl.setBackground(Color.RED);

              f.addMouseWheelListener(new AWTTest6());
              pnl.addMouseWheelListener(new AWTTest6());
              btn.addMouseWheelListener(new AWTTest6());

              pnl.add(btn);
              f.add(pnl);

              f.setSize(400, 400);
              f.setVisible(true);
          }
          public void mouseWheelMoved(MouseWheelEvent e) {
              System.out.println("mouseWheelMoved on " + e.getComponent().getName());
              //e.consume();
          }
      }

      The behavior can be worked-around by using MouseWheelEvent.consume().

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dav Andrei Dmitriev (Inactive)
              Reporter:
              bchristi Brent Christian
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: