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

MouseDragged confined to JFrame after JMenu dismissal.

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Linux (X11 based systems)

      A DESCRIPTION OF THE PROBLEM :
      On Linux (X11 based systems), when a user clicks inside a JFrame to close an open JMenu or JPopupMenu and maintains the mouse button press to begin a drag, the subsequent MouseDragged events are incorrectly confined to the boundaries of the JFrame. The registered MouseMotionListener stops receiving events the moment the cursor moves outside the window.

      This is a regression from the expected AWT/Swing behavior, which should maintain mouse input delivery to the originating component for the duration of the drag, regardless of window boundaries. Windows exhibits the correct behavior in the same test case.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Use the provided Java test case code (below).
      2. Run the application on a Linux system.
      3. Baseline Test (Expected Behavior):
          a. Click inside the frame content pane (press the mouse button down).
          b. Drag the cursor outside the JFrame boundary.
          c. Verify: mouseDragged messages continue to be printed to the console (Correct).
          d. Release the mouse button.
      4. Bug Reproduction Test (Failing Behavior):
          a. Click the "File" menu item to open the JMenu.
          b. Click an empty area inside the JFrame to close the menu/popup, but do not release the mouse button (maintain the press).
          c. While still pressing the mouse button, drag the cursor outside the JFrame boundary.
          d. Verify: mouseDragged messages cease immediately upon the cursor crossing the window border. (Incorrect on Linux).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The MouseMotionListener should continue to receive mouseDragged events when the cursor is moved outside the JFrame boundaries, just as it does during an uninterrupted drag sequence and as it does on Windows.
      ACTUAL -
      On Linux only, mouseDragged events cease the moment the cursor crosses the JFrame border when the drag is initiated by the click that closes the menu/popup.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.MouseEvent;

      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;
      import javax.swing.event.MouseInputAdapter;

      public class MouseDragPopupBug {

      public static void main(final String[] args) {

      SwingUtilities.invokeLater(() -> {
      final JFrame frame = new JFrame(MouseDragPopupBug.class.getSimpleName());
      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      frame.getContentPane().addMouseMotionListener(new MouseInputAdapter() {

      @Override
      public void mouseDragged(final MouseEvent e) {
                                            // NOTE: This should print regardless of whether the mouse is inside or outside the JFrame boundary
      System.out.println("MOUSE DRAGGED [" + e + "]");
      }
      });

      final JMenuBar menuBar = new JMenuBar();

      final JMenu fileMenu = new JMenu("File");
      fileMenu.add(new JMenuItem("Open"));

      menuBar.add(fileMenu);

      frame.setJMenuBar(menuBar);

      frame.setSize(500, 500);
      frame.setVisible(true);
      });
      }
      }
      ---------- END SOURCE ----------

            azvegint Alexander Zvegintsev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: