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();
}
}