JDK-6753637 : Windows LNF prevents mousePressed() from being called when JPopupMenuvisible
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2008-09-29
  • Updated: 2017-05-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_10-rc2"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc2-b32)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
In JRE6.0_u10(b32), if the Windows LNF is being used, and a JPopupMenu is being displayed, a mouse click does not cause MouseListener.mousePressed() to be called. MouseListener.mouseReleased() is called, however.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Right-click should display popup, left-click should dismiss popup.

Java console should display a message for each of mousePressed and mouseReleased for each click.
ACTUAL -
Left click just re-displays popup in new location.

No message for mousePressed once a right-click has occurred.

REPRODUCIBILITY :
This bug can be reproduced always.

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

/**
 * Test case for Windows LNF popup bug
 *
 * Right-click shows popup. Left-click should dismiss it. In JRE6.0u10(b32) it not.
 */
public class TestPopups extends JApplet {

    private class TestPanel extends JPanel {

        public TestPanel() {
            final JPopupMenu popup = new JPopupMenu();
            popup.add("Test");

            addMouseListener(new MouseAdapter() {
                    private boolean isPopupTrigger_;

                    public void mousePressed(MouseEvent evt) {
                        System.out.println("In mousePressed");
                        isPopupTrigger_ = evt.isPopupTrigger();
                    }

                    public void mouseReleased(MouseEvent evt) {
                        System.out.println("In mouseReleased");
                          isPopupTrigger_ = isPopupTrigger_ || evt.isPopupTrigger();
                          if (isPopupTrigger_)
                              popup.show(TestPanel.this, evt.getX(), evt.getY());
                    }
            });
        }
    }

    public void init() {
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    }
                    catch (Exception ex1) {
                        System.out.println("Unsupported LookAndFeel");
                    }
                    getContentPane().add(new TestPanel());
                }
            });
    }
}

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

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

Comments
EVALUATION It may be L&F specific, but it was introduced in 6u10 b26 as part of 6646781:Nimbus L&F : Menu stays open when continously clicked on internal frame icon on Windows & nimbus L&F ie until b26 "left click" does not redisplay the popup, it just dismisses it. Perhaps this is an unintentional side effect of the above fix, please re-evaluate why the old behaviour was wrong in this context. If the previous behaviour was correct, then this is a bug. If the previous behaviour was a bug, then this is not a regression, its a fix, and the regression keyword should be removed.
17-11-2008

EVALUATION see BasicPopupMenuUI.MouseGrabber.eventDispatched() // Ask UIManager about should we consume event that closes // popup. This made to match native apps behaviour. boolean consumeEvent = UIManager.getBoolean("PopupMenu.consumeEventOnClose"); WindowsLookAndFeel defines "PopupMenu.consumeEventOnClose" as true, this matches the native apps behaviour, when Metal LaF sets it to false This is a LaF specific behaviour, closed as not bug
10-11-2008

EVALUATION The behavior is not java Plug-in related. The same behavior is in the standalone application. Reassing to swing team for further evaluation.
24-10-2008