JDK-8029686 : [macosx] PopupMenu's MenuItem is not fired if the PopupMenu is shown from a JWindow
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-09-26
  • Updated: 2014-03-13
  • Resolved: 2014-03-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
The action on a PopupMenu's MenuItem is not fired if the PopupMenu is shown from a JWindow.

REGRESSION.  Last worked in version 7u40

REGRESSION : Additional Information
I know JDK6 works.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run the code in the description, click on the "Click me' Button, a window will show, click the "Button" button again, a popup menu will show up. Clicking on the only MenuItem, nothing happens.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The correct behavior is to see a message box.
ACTUAL -
Nothing happened. The registered action for the MenuItem is not triggered

ERROR MESSAGES/STACK TRACES THAT OCCUR :
/**
 * Copyright (c) 2007 NoMagic, Inc. All Rights Reserved.
 */

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

public class PopupMouseEventDemo extends JFrame {

    public PopupMouseEventDemo() {
        JButton button = new JButton("Click me");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                createMenu();
            }
        });

        setMinimumSize(new Dimension(300, 300));
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel panel = new JPanel(new BorderLayout());
        panel.add(button, BorderLayout.NORTH);


        add(panel);
        setVisible(true);
    }

    private void createMenu() {
        final JWindow popup = new JWindow();
        popup.getContentPane().setLayout(new BorderLayout());

        final JButton button = new JButton("Button");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JPopupMenu popupMenu = new JPopupMenu();
                JMenuItem menuItem = new JMenuItem(new AbstractAction("MenuItem") {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(null, "Clicked");

                    }
                });
                popupMenu.add(menuItem);
                popupMenu.show(button, 0, popup.getPreferredSize().height);
            }
        });

        popup.getContentPane().add(button);
        popup.pack();
        popup.setLocationRelativeTo(PopupMouseEventDemo.this);
        popup.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new PopupMouseEventDemo();
            }
        });
    }
}


REPRODUCIBILITY :
This bug can be reproduced always.
Comments
This problem and JDK-8032872 have the same root cause. This will be fixed by the changes for JDK-8032872. Closing as dupe of JDK-8032872.
13-03-2014

Release team: Approved for deferral.
06-12-2013

Defer justification: Not a regression (reproducible since 7GA), not critical. Only Swing popup menus in JWindow are affected. AWT popup menus work fine in the same case, so there's an easy workaround - use AWT popup menus in a JWindow.
06-12-2013

defer candidate as not a P2 and not a stopper?
06-12-2013

The issue is reproducible with JDK 8. On my machine it's also reproducible with starting from 7u6, so the bug description is incorrect. The issue is only reproducible with JWindow.
06-12-2013

it seems not critical, please evaluate
06-12-2013