JDK-6789982 : Clicking away a popup menu consumes the mousePressed event in the Windows LAF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2009-01-05
  • Updated: 2011-01-19
  • Resolved: 2009-01-13
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
java version "1.6.0_12-ea"
Java(TM) SE Runtime Environment (build 1.6.0_12-ea-b03)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)



ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]

A DESCRIPTION OF THE PROBLEM :
A regression occurs when canceling a popup menu by clicking on a component.
Normally that component receives a mousePressed event.
This is not the case for the Windows look and feel since update 10.
It works fine in update 7, other look and feels and other operating systems.

This bug forces the user to click twice to initiate any action while dismissing a popup menu.
Note that subsequent mouseDragged events are reported correctly, but without a mousePressed to begin with.

A simple real-life use case of acting upon the dismissal of a popup menu is to right-click on the Windows desktop and then afterwards selecting some icons on it. It would be awkward to have to click once to dismiss the menu and again to start a drag operation or select an object.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- add a mouse listener to a panel
- create a popup menu and show it on the panel
Click outside of the menu but inside the panel.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The menu is dismissed and the mouse event is reported.
ACTUAL -
The menu is dismissed but the mouse event is not reported.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class TestEvent {

    public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, IllegalAccessException, InstantiationException {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

        final JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(200, 100));
        panel.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON3) {
                    JPopupMenu menu = new JPopupMenu();
                    menu.add("Left-click outside of the menu");
                    menu.show(panel, e.getX(), e.getY());
                }
            }

            public void mousePressed(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) System.out.println("Left click detected.");
            }

            public void mouseReleased(MouseEvent e) {
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }
        });
        JFrame frame = new JFrame();
        frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true);
    }
}


---------- END SOURCE ----------

Release Regression From : 6u10
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.