Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8029686

[macosx] PopupMenu's MenuItem is not fired if the PopupMenu is shown from a JWindow

XMLWordPrintable

      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.

            dmarkov Dmitry Markov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: