JDK-4616935 : MouseWheelEvents propagated to too many listeners
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0,1.4.2,5.0,6
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    linux_sun,windows_nt,windows_2000,windows_xp linux_sun,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-12-21
  • Updated: 2006-10-23
  • Resolved: 2006-10-23
Related Reports
Duplicate :  
Relates :  
Relates :  
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().

Comments
EVALUATION It's a native Windows behaviur : it posts WM_MOUSE_WHEEL to every container under particular component, i.e. if a Frame contains a Button in it then native system would send WHEEL event to both. This could easily be demonstrated with SPY++. I predict that the fix for this problem is far from the easiest one because we should keep track on event sequence(skip all events except first), component hierarchy. There are also edge situations such as using wheel while moving the mouse. With regard to priority, votes, existing time, estimated fix complexity and to the nature of this CR I'd not fix it. We reopen this once get a complainment again. The opened issue is that Swing is receiving only one event.
23-10-2006

EVALUATION On windows: every component is propagating wheel events to it's parent. Linux/Solaris - wheel event is only comes to the component where mouse currently located. Note that if even component doesn't have a listener on it (like Scrollbar in 4786832) it may still propagate the events to parent. Whereas this looks like more suitable for users there is no much activity around this. I'd consider this like a defect on Windows implementation for now.
20-10-2006

EVALUATION Transfering wheel events up the hierarchy say from the button to panel and then to frame may have sense. Please rotate the wheel in some browser window. If the widget having focus or having mouse cursor over it isn't supposed to handle wheel events (such as a TextComponent without scrollbar, a Button etc.) then they might be forwarded to parent. This allows browser to make scrolling regardless of current focused component. From this point of view Win32 behaviour more correct and suitable then Linux one.
02-10-2006

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=14106
08-07-2006

WORK AROUND Call consume() on the MouseWheelEvent to prevent further propagation. ###@###.### 2001-12-20
20-12-2001