JDK-4991772 : REGRESSION: Putting a JButton in a submenu of a JPopupMenu causes glitch
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-02-10
  • Updated: 2005-12-23
  • Resolved: 2005-12-23
Related Reports
Duplicate :  
Description
Name: rmT116609			Date: 02/09/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 2000 SP4

A DESCRIPTION OF THE PROBLEM :
Placing a JButton in a submenu of a JPopupMenu causes a strange glitch where clicking the button causes it to get pressed down but it doesn't fire an action event and stays stuck pressed down.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run included code under jdk 1.5
2) Right-click anywhere in the JFrame that appears
3) Select the subMenu item, which opens up a sub menu
4) Click the "Click me" button

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Button gets pressed and then pops up again and an actionEvent is fired (console should print "Clicked")
ACTUAL -
Button gets pressed, stays stuck pressed and no event is fired

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;

public class PopupButtonTest
{

  public static void main(String[] args)
  {
    JFrame jf = new JFrame("PopupButtonTest");

    jf.getContentPane().addMouseListener(new MouseAdapter()
    {
      public void mouseClicked(MouseEvent e)
      {
        handle(e);
      }

      public void mousePressed(MouseEvent e)
      {
        handle(e);
      }

      public void mouseReleased(MouseEvent e)
      {
        handle(e);
      }

      private void handle(MouseEvent e)
      {
        if (e.isPopupTrigger())
        {
          JPopupMenu jpm = new JPopupMenu();
          JButton but = new JButton("Click me");
          but.addActionListener(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              System.out.println("Clicked!");
            }

          });
          JMenu jm = new JMenu("subMenu");
          jm.add(but);
          jpm.add(jm);
          jpm.show((Component) e.getSource(), e.getX(), e.getY());
        }
      }

    });

    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(100, 100);
    jf.setVisible(true);
  }


}

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

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 237606) 
======================================================================

Comments
EVALUATION Fixed as a part of fix for 5036146: REGRESSION: problems with 1.5.0 action listeners
23-12-2005

EVALUATION Name: azR10139 Date: 02/25/2004 Too late and too risky to fix this problem in 1.5. Will be fixed in the next release. ###@###.### 02/25/2003 ======================================================================
25-02-2003