Click to See Complete Forum and Search --> : Adding MouseListener to a combobox


beginner
September 29th, 1999, 08:39 AM
I have the following sample code to capture mouse events in a combobox.

import java.awt.event.*;
import javax.swing.*;
.
.
.
.
JComboBox comboObject = new JComboBox();
comboObject.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
//Execute some code
}
}
});

But nothing seems to be working. Is it because comboboxes do not listen to low_level events such as mouse, focus and key events ?

I want the drop_down list in the combobox to listen for mouse events. The problem is that when any item in the drop_down list is double_clicked the component present below the combobox gets invoked. i.e., if in a gridbaglayout you have the combobox placed above a Jlist then the Jlist's item gets selected when you double click in a combobox.

poochi
September 29th, 1999, 09:18 PM
>. The problem is that when any item in the drop_down list is double_clicked the component present
>below the combobox gets invoked. i.e., if in a gridbaglayout you have the combobox placed above a
>Jlist then the Jlist's item gets selected when you double click in a combobox.

It's because , ComboBox's list portion has been added inside a popupmenu( BasicComboPopup
derived from JPopupMenu ). If you click on the arrow button , this BasicComboPopup is
being shown. I dont think you can trap double click in JPopup menu ( if i am wrong please
some one correct me .. ).