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

JPopupMenu is inadvertently shown when using setComponentPopupMenu

    XMLWordPrintable

    Details

    • Subcomponent:
    • Understanding:
      Cause Known
    • Introduced In Version:
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_152-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_152-ea-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

      macOS Sierra 10.12.6 (16G29)

      A DESCRIPTION OF THE PROBLEM :
      I am seeing an issue when using setComponentPopupMenu.

      When you use setComponentPopupMenu in a window and create a modeless dialog and position that over that window. A contextual menu click in the modeless dialog will show the contextual men of the component in the parent window when that parent window has the focus.

      I traced the issue down to processMouseEvent in the Container class. There, a call is made to trackMouseEnterExit which will create and dispatch a MouseEvent.MOUSE_ENTERED mouse event.

      This generated mouse event still has the isPopupTrigger attribute set to true which will then triggers the componentPopupMenu to be shown.

      REGRESSION. Last worked in version 8u121

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_74"
      Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Run the test program
      - Want until the modeless dialog is shown on top of the main frame.
      - Make sure the main frame has the focus
      - Do a contextual menu click inside the modeless dialog.
      - The JPopupMenu that was installed on the main frame's root pane is shown

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JPopupMenu that was installed on the main frame's root pane should not be shown
      ACTUAL -
      The JPopupMenu that was installed on the main frame's root pane is shown

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.JMenuItem;
      import javax.swing.JPopupMenu;
      import javax.swing.JTextArea;
      import javax.swing.SwingUtilities;

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

      private static void test() {
      JPopupMenu popupMenu = new JPopupMenu();
      popupMenu.add(new JMenuItem("You should not see me"));

      JFrame frame = new JFrame("Main Frame");
      frame.getRootPane().setComponentPopupMenu(popupMenu);
      frame.setSize(400, 400);
      frame.setLocation(0, 0);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

      JTextArea info = new JTextArea("Do a contextual mouse click here while the Main Frame is active");
      info.setWrapStyleWord(true);
      info.setLineWrap(true);

      JDialog dialog = new JDialog(frame, "Modeless Dialog", false);
      dialog.getContentPane().add(info);
      dialog.setSize(300, 300);
      dialog.setLocation(50, 50);
      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      dialog.setVisible(true);

      frame.toFront();
      }
      }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated: