Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6776674

JComboBox does not deliver MOUSE_CLICKED events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6u10
    • client-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux unixdev 2.6.23.1-49.fc8 #1 SMP Thu Nov 8 22:14:09 EST 2007 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      JComboBox doesn't fire a MOUSE_CLICKED event if the event opens or closes the combo box's dropdown list. This leads, among other things, to an inability to successfully listen for double-click events with the left mouse button on JComboBoxes because the clickCount for all mouse events is never greater than 1 in this case.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the sample code provided. Perform a double-click with the left mouse button on the displayed combo box.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the following events to be received and printed by the toolkit listener:

      1. MOUSE_PRESSED (clickCount: 1)
      2. MOUSE_RELEASED (clickCount: 1)
      3. MOUSE_CLICKED (clickCount: 1)
      4. MOUSE_PRESSED (clickCount: 2)
      5. MOUSE_RELEASED (clickCount: 2)
      6. MOUSE_CLICKED (clickCount: 2)
      ACTUAL -
      4 events are received and printed by the toolkit listener:

      1. MOUSE_PRESSED (clickCount: 1)
      1. MOUSE_RELEASED (clickCount: 1)
      1. MOUSE_PRESSED (clickCount: 1)
      1. MOUSE_RELEASED (clickCount: 1)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.AWTEvent;
      import java.awt.Dimension;
      import java.awt.Toolkit;
      import java.awt.event.AWTEventListener;
      import java.awt.event.MouseEvent;

      import javax.swing.JComboBox;
      import javax.swing.JFrame;

      public class JComboBoxClickTest {

          public static void main(String[] args) {

              String [] comboItems = new String [] {"1", "2", "3"};
                      
              
              JFrame frame = new JFrame();
              frame.setTitle("JComboBox click test");

              JComboBox combo =
                  new JComboBox(comboItems);
              combo.setEditable(false);
              combo.setPreferredSize(
                      new Dimension(100, 50));
              frame.getContentPane().add(combo);

              Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

                  public void eventDispatched(AWTEvent event) {
                      if (event instanceof MouseEvent
                              && ((MouseEvent)event).getClickCount() > 0) {

                          System.out.println(event);
                      }
                  }
                  
              }, AWTEvent.MOUSE_EVENT_MASK);

              frame.pack();
              frame.setVisible(true);
          }

      }
      ---------- END SOURCE ----------

            dav Andrei Dmitriev (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: