-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
1.2.1
-
generic
-
generic
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)
======================================================================
- duplicates
-
JDK-4144505 Compound components don't behave properly
-
- Closed
-