JDK-8080137 : Dragged events for extra mouse buttons (4,5,6) are not generated on JSplitPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,8u45,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-05-08
  • Updated: 2015-09-29
  • Resolved: 2015-05-22
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.
JDK 8 JDK 9
8u60Fixed 9 b68Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
Windows 7 Ultimate 64 bit SP1

EXTRA RELEVANT SYSTEM CONFIGURATION :
Use a mouse that has more than 3 buttons, i.e. like the Microsoft Intellimouse.
The MS drivers are correctly installed for that mouse, and all buttons are recognized properly by the OS.

A DESCRIPTION OF THE PROBLEM :
MouseDragged events are not generated when using extra mouse buttons (i.e. 4, 5, 6) on a component that is part of a JSplitPane.

When dragging with mouse button (1,2,3), we can see MouseDragged events.
But, when dragging with extended mouse buttons (4,5,6),  no dragged events are fired, even though MousePressed and MouseReleased are.

Note that dragging with the extended mouse buttons on a normal JPanel that is not part of a JSplitPane hierarchy produces the drag event correctly for button 4,5,6.

So, it looks like that 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached Swing application
2. Using mouse button 4, drag the mouse on the top gray area 
3. Observe the console with java.awt.event.MouseEvent[MOUSE_DRAGGED events
4. Using mouse button 4, drag the mouse on the yellow area (which is part of the JSplitPane), observe that the console does not show any drag events.

This is problematic since our application needs to listen for drag events for extended buttons on components that are part of a JSplitPane.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
areExtraMouseButtonsEnabled=true
numberOfButtons=5

Observe the console with java.awt.event.MouseEvent[MOUSE_DRAGGED events when dragging with mouse button 4 over the yellow area (i.e. inside the JSplitPane)
ACTUAL -
areExtraMouseButtonsEnabled=true
numberOfButtons=5

No drag events are generated when dragging with mouse button 4 over the yellow area (i.e. inside the JSplitPane)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
-----------MouseApp.java------------------

import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;


public class MouseApp {

	public static void main(String[] args) 
	{
		SwingUtilities.invokeLater( () -> {
		    buildTestApp();			
		});
	}
	
	private static void buildTestApp() {
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		boolean areExtraMouseButtonsEnabled = Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled();
		System.err.println("areExtraMouseButtonsEnabled=" + areExtraMouseButtonsEnabled);
		int numberOfButtons = MouseInfo.getNumberOfButtons();
		System.err.println("numberOfButtons=" + numberOfButtons);

		Toolkit.getDefaultToolkit().addAWTEventListener(
				new AWTEventListener() {
					@Override
					public void eventDispatched(AWTEvent event) {
						System.err.println(event);
					}
				},
				MouseEvent.MOUSE_EVENT_MASK | 
				MouseEvent.MOUSE_MOTION_EVENT_MASK | 
				MouseEvent.MOUSE_WHEEL_EVENT_MASK);

		JPanel container = new JPanel(new BorderLayout());
		
		JLabel label = new JLabel("Mouse Button 4 drag DOES NOT WORK here !");
		label.setFont(label.getFont().deriveFont(35f));
		
		JPanel problematicArea = new JPanel();
		problematicArea.setLayout(new BorderLayout());
		problematicArea.add(label, BorderLayout.CENTER);
		problematicArea.setBackground(Color.yellow);

		JLabel topLabel = new JLabel("Mouse Button 4 drag works here");
		topLabel.setFont(topLabel.getFont().deriveFont(48f));
		topLabel.setHorizontalTextPosition(SwingConstants.CENTER);

		JSplitPane splitPane = new JSplitPane();
		splitPane.setRightComponent(problematicArea);
		splitPane.setLeftComponent(new JButton("Bro"));

		container.add(splitPane, BorderLayout.CENTER);
		container.add(topLabel, BorderLayout.NORTH);

		f.setContentPane(container);
		f.setSize(1024, 768);
		f.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
We installed our own custom event queue, and intercepting mouse dragged events at that level for all mouse buttons.

This is far from being ideal since the source of the event is not correct (i.e. the source is the frame itself instead of being the component itself)


Comments
Container.isMouseGrab(MouseEvent) method does not take into account the extended modifiers for additional buttons.
18-05-2015

There is updated test. if MouseMotionListener is added to a JPanel then MouseDragged is not generated for buttons (4, 5, 6). -------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MouseDraggedTest { private static final boolean ADD_MOUSE_MOTION_LISTENER = true; public static void main(String[] args) { Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { System.err.println(event); } }, MouseEvent.MOUSE_EVENT_MASK | MouseEvent.MOUSE_MOTION_EVENT_MASK | MouseEvent.MOUSE_WHEEL_EVENT_MASK); SwingUtilities.invokeLater(MouseDraggedTest::createAndShowGUI); } static void createAndShowGUI() { JFrame frame = new JFrame(); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); if (ADD_MOUSE_MOTION_LISTENER) { panel.addMouseMotionListener(new MouseAdapter() { @Override public void mouseDragged(MouseEvent e) { System.out.println("Mouse Dragged!"); } }); } frame.add(panel); frame.setVisible(true); } } --------------------------------
15-05-2015