JDK-8369028 : MouseDragged confined to JFrame after JMenu dismissal.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,21,25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86_64
  • Submitted: 2025-09-30
  • Updated: 2025-10-03
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.
Other
tbdUnresolved
Description
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 ----------


Comments
Observations on Ubuntu 24.04: - JDK 8u461: Failed, mouseDragged event cease after cursor crosses the JFrame - JDK 25+37-LTS-3491: Failed, mouseDragged event cease after cursor crosses the JFrame As submitter said, issue is not reproducible on macOS or Windows.
01-10-2025

I -> M (Somewhere in between) L -> L (Uncommon use case) W -> H (No workaround) Priority -> MLH -> P4
01-10-2025