JDK-4245285 : ability to use addMouseListener with JComboBox
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-06-09
  • Updated: 1999-11-29
  • Resolved: 1999-11-29
Related Reports
Duplicate :  
Description

Name: skT88420			Date: 06/09/99


Adding a mouse listener to a JComboBox does not appear to work.
I susect this has to do with having a render Component which
is really getting the mouse events wither than the JComboBox.
Here is a simple piece of code.  The popup menu appears over
the JTextField, but not the JComboBox.  This problem also
occurs with the Solaris Production JDK.

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;

public class test extends JPanel {

    JPopupMenu p = null;

    class PopupAdapter extends MouseAdapter {
        public void mousePressed(MouseEvent e) {
            if(e.isPopupTrigger()) {
                p.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    }

    public test () {
        JComboBox b = new JComboBox();
        b.addItem("abc");
        b.addItem("def");
        add(b);
        JTextField t = new JTextField(10);
        add(t);
        p = new JPopupMenu();
        p.add("hij");
        p.add("klm");
        PopupAdapter pa = new PopupAdapter();
        b.addMouseListener(pa);
        t.addMouseListener(pa);
    }

    static public void main(String args[]) {
        JFrame f = new JFrame("test");
        test t = new test();
        f.setContentPane(t);
        f.pack();
        f.show();
    }
}
(Review ID: 84156) 
======================================================================

Comments
EVALUATION This is a duplicate bug of 4144505. It's not a problem with combo box. It's a problem with all Java components that are composed of other Java components. tom.santos@eng 1999-11-29
29-11-1999