JDK-6788487 : Mouse Listener doesn't recognize mouse pressed event after using setLookAndFeel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-12-23
  • Updated: 2011-01-19
  • Resolved: 2008-12-25
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Window XP SP2

A DESCRIPTION OF THE PROBLEM :
After using UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

Mouse Listener of a JPanel won't recognize mouse pressed correctly.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Enclosed is a short test program, which works fine under 6u7 but fails under 6u10.

Here are the test steps :

1.	Click on ���menu��� but don���t click on any menu items.
2.	Move mouse to the white area (JPanel)
3.	Click mouse once. Nothing happens but it should draw a red dot. The mouse listener does not recognize the first click. The subsequent clicks are fine.

If you perform this test under 6u7, it works fine. If you take out setLookAndFeel, it works fine also.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Mouse Pressed even should be recognized all time

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class MouseClickTest  extends JFrame
{
	static int sxw=800;
	static int sxh=800;
	int mx, my;
	JPanel jpl;
	public MouseClickTest()
	{
		init();
	}
	private void init()
	{
		jpl =new JPanel()
		{
			public void paintComponent(Graphics g)
			{
				Graphics2D g2=(Graphics2D) g;
				g2.setColor(Color.white);
				g2.fillRect(0,0,800,800);
				if ( mx > 0 && my > 0 )
				{
					g2.setColor(Color.red);
					g2.fillOval(mx,my, 20,20);
				}
			}
		};
		jpl.setPreferredSize(new Dimension(sxw, sxh));
		jpl.addMouseListener(new MouseAdapter(){
		public void mousePressed(MouseEvent e)
		{
			mx=e.getX();
			my=e.getY();
			jpl.repaint();
		}
		}
		);
		JMenuBar mb = new JMenuBar();
        		JMenu menu = new JMenu("menu");
        		for(int i=0; i<5; i++)
			menu.add(new JMenuItem("Item "+i));
        		mb.add(menu);
 		setJMenuBar(mb);
		
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(jpl, BorderLayout.CENTER);
		setSize(800,800);
		pack();
		setVisible(true);
		 addWindowListener(new WindowAdapter() {
            	public void windowClosing(WindowEvent ev) {
                		System.exit(0);
            	}
        		});
	}
	public static void main(String[] args)
	{
		try {
			//this is ok.
			//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
			//these are bad
			//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	          		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    		}
    		catch (Exception e) {	}
		SwingUtilities.invokeLater(new Runnable()
		{
    			public void run()
			{
				new MouseClickTest();
			}
   		});
    	}
}
---------- END SOURCE ----------