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

JPopupMenu is inadvertently shown when using setComponentPopupMenu when mouse is dragged from one component to another

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8, 9, 10, 11
    • client-libs

      FULL PRODUCT VERSION :
      ubuntu 16.04

      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, then when mouse is dragged with the left button pressed, to the modeless dialog from the parent window, and then the right button is immediately pressed,
      then the popup is fleetingly shown.

      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
      - Drag mouse with left button pressed and when the mouse is in modeless dialog, immediately press right button.
      - The JPopupMenu that was installed on the main frame's root pane is shown fleetingly.

      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 ----------

            Unassigned Unassigned
            psadhukhan Prasanta Sadhukhan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: