JDK-4517826 : MouseEvent ex-modifiers not delivered correctly to lightweight comps.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: generic
  • Submitted: 2001-10-22
  • Updated: 2001-11-15
  • Resolved: 2001-11-15
Related Reports
Duplicate :  
Description
The BUTTONX_DOWN_MASK is still set in the MouseEvent when mouseReleased is
called.  This only happens when the component is a lightweight component.
If you modify the test program below to use a Button instead of a JButton 
the BUTTONX_DOWN_MASK will not be set when mouseReleased is called.  This
is reproducible under both Windows2000 and Linux.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MaskTest extends Frame {
    public MaskTest() {
        super("Mask Test.");
        setSize(400, 400);
        //Button button = new Button("Check Me Out");
        JButton button = new JButton("Check Me Out");
        add(button);

        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
            public void eventDispatched(AWTEvent e) {
                if (e instanceof MouseEvent) {
                    MouseEvent ev = (MouseEvent)e;
                System.out.println("AWT EVENT LISTENER BUTTON1_DOWN_MASK? " +
                    ((ev.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==
                        InputEvent.BUTTON1_DOWN_MASK));
                }
            }
        }, AWTEvent.MOUSE_EVENT_MASK);
            
        button.addMouseListener(new MouseAdapter()  {
            public void mousePressed(MouseEvent e) {
                System.out.println("Mouse Pressed");
                System.out.println("-------------");
                System.out.println("BUTTON1_DOWN_MASK? " +
                    ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==
                        InputEvent.BUTTON1_DOWN_MASK));
                System.out.println("-------------");
            }

            public void mouseReleased(MouseEvent e) {
                System.out.println("Mouse Released");
                System.out.println("--------------");
                System.out.println("BUTTON1_DOWN_MASK? " +
                    ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) ==
                        InputEvent.BUTTON1_DOWN_MASK));
                System.out.println("--------------");
            }
        });
        setVisible(true);
    }

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

Comments
WORK AROUND When a mouse button is released, MouseEvent.getModifiers() returns the BUTTONX_MASK for the released button, event thought getModifiersEx() still reports the button being down. ###@###.### 2001-10-22
22-10-2001

EVALUATION This is a bug - see JavaDoc for InputEvent.getModifiersEx(). getModifiersEx() has behaved this way since it was added in b75. A possible work-around is to check for a button's release by checking the BUTTONX_MASK of the MOUSE_RELEASED event, rather than BUTTONX_DOWN_MASK. ###@###.### 2001-10-22 This was fixed as part of 4508327. Closing. ###@###.### 2001-11-14
22-10-2001