JDK-6534284 : setAutoscrolls(true) eats mouse events when it shouldn't
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-03-14
  • Updated: 2011-02-16
  • Resolved: 2007-10-25
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When the setAutoScrolls(true) method is called, events generated inside a component are not sent to the parent component when there are no listeners present.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run test case, click inside red box.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
should print 'mouse pressed in outer panel'
ACTUAL -
doesnt print anything

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MouseTest extends JFrame{
	public MouseTest() {
		super("PanelList test");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(500, 500);

		JComponent outerPanel = new JPanel();
		JComponent innerPanel = new JPanel();

		outerPanel.setPreferredSize(new Dimension(400,400));
		innerPanel.setPreferredSize(new Dimension(300,300));

		outerPanel.setBackground(Color.GREEN);
		innerPanel.setBackground(Color.RED);

		innerPanel.setAutoscrolls(true);

		outerPanel.add(innerPanel);
		outerPanel.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				System.out.println("mouse pressed in outer panel");
			}
		});

		add(outerPanel);
		setVisible(true);
	}
	public static void main(String[] args) {
		new MouseTest();
	}
}

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

CUSTOMER SUBMITTED WORKAROUND :
adding a mouse listener to the inner panel, refiring events to the outer panel

Comments
EVALUATION This is exactly the same issue as described in the CR #4413412 We enable mouseEvents when autoscroll is on anyway you shouldn't rely on the "mouseEvent transparency" see more info in the evaluation for the CR #4413412
25-10-2007