CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 1999
    Posts
    25

    Adding MouseListener to a combobox

    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.




  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Adding MouseListener to a combobox


    >. 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 .. ).





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured