JDK-4648623 : JComboBox MouseListener behavior different between Windows and Metal
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-03-07
  • Updated: 2002-04-20
  • Resolved: 2002-04-20
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 03/06/2002


FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

FULL OPERATING SYSTEM VERSION : W2000 SP2




A DESCRIPTION OF THE PROBLEM :
When you add a Mouse Listener to a JComboBox (e.g. for a
popup Window),
everything works fine with Windows Look and Feel.
In Metal Look and Feel, the mouse listener ignored.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile with UIManager Metal/Windows
2. right click on components
3. No popup on Metal JComboBox, but one on Windows

EXPECTED VERSUS ACTUAL BEHAVIOR :
Mouse Listener should work on Metal

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/**
 *  Mouse Listener on JComboBox bug:
 *  Java 1.4.0 RC
 *  When you add a Mouse Listener to a JComboBox (e.g. for a popup Window),
 *  everything works fine with Windows Look and Feel.
 *  In Metal Look and Feel, the mouse listener is ignored
 *
 * Testcase:
 * - emable or disable setting the Look and Feel in the main method
 * - compile and run java SwingBug.class
 * - right-click on the different components
 * - if Windows, you get a popup window on the top ComboBox and on the label
 * - if Metal, you get the a popup window only on the label
 */

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class SwingBug extends JFrame implements MouseListener, ActionListener
{
	public static void main(String[] args)
	{
		try {
			UIManager.setLookAndFeel
(UIManager.getSystemLookAndFeelClassName());
			System.out.println(UIManager.getLookAndFeel().toString
());
		} catch (Exception e) {}
		new SwingBug();
	}

	private JComboBox jComboBox1 = new JComboBox();
	private JComboBox jComboBox2 = new JComboBox();
	private JPopupMenu jPopupMenu1 = new JPopupMenu();
	private JMenuItem jMenuItem1 = new JMenuItem();
	private JMenuItem jMenuItem2 = new JMenuItem();
	private JLabel jLabel1 = new JLabel();

	public SwingBug()
	{
		System.out.println(java.util.Locale.US);
		try
		{
			setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			jbInit();
			pack();
			show();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	private void jbInit() throws Exception
	{
		jComboBox1.addItem("one");
		jComboBox1.addItem("two");
		jComboBox1.addItem("three");
		jComboBox2.addItem("X one");
		jComboBox2.addItem("X two");
		jComboBox2.addItem("X three");
		jMenuItem1.setText("PopUpMenu1");
		jMenuItem2.setText("PopUpMenu2");
		jLabel1.setText("jLabel1");

		this.getContentPane().add(jComboBox1,  BorderLayout.NORTH);
		this.getContentPane().add(jComboBox2,  BorderLayout.SOUTH);
		this.getContentPane().add(jLabel1, BorderLayout.CENTER);
		jPopupMenu1.add(jMenuItem1);
		jPopupMenu1.add(jMenuItem2);
		//
		jLabel1.addMouseListener(this);
		jComboBox1.addMouseListener(this);
	}

	public void mouseClicked(MouseEvent e)
	{
		System.out.println ("mouseClicked on " + e.getSource().getClass
().toString());
		if (SwingUtilities.isRightMouseButton(e))
			jPopupMenu1.show((Component)e.getSource(), e.getX(),
e.getY());
	}
	public void mousePressed(MouseEvent e)
	{
	//	System.out.println ("mousePressed on " + e.getSource().getClass
().toString());
	}
	public void mouseReleased(MouseEvent e)
	{
	//	System.out.println ("mouseReleased on " + e.getSource().getClass
().toString());
	}
	public void mouseEntered(MouseEvent e)
	{
	//	System.out.println ("mouseEntered on " + e.getSource().getClass
().toString());
	}
	public void mouseExited(MouseEvent e)
	{
	//	System.out.println ("mouseExited on " + e.getSource().getClass
().toString());
	}
	public void actionPerformed(ActionEvent e)
	{
		System.out.println ("actionPerformed from " + e.getSource
().getClass().toString());
	}

}   //  SwingBug


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

CUSTOMER WORKAROUND :
Trying to find it in UI Delegate. Not found yet.
(Review ID: 139091) 
======================================================================

Comments
EVALUATION This bug is a duplicate of 4144505.
24-08-2004