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

Clicking on an editable JComboBox leaves JPopupMenus and other menus open

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 5.0, 6, 7, 8
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Clicking in an editable JComboBox leaves a JPopupMenus or other menu open.

      The problem can be seen in the BasicPopupMenuUI code. If the "doNotCancelPopup" property is set on the clicked component, the popup menu will not be cancelled. Clearly this was intended to stop the combo box list popup from closing, but instead it stops almost ALL popups from closing.

      This bug has been there since at least Java 1.5.

      The bug becomes a real problem if a popup menu (apart from the combo list) is opened on the editing component of the combo box - something like a "Cut", "Copy", "Paste" etc. context menu, in which enabled components depend on whether or not there is a selection in the editing component, etc. Now that state can change while the popup is showing, since the user can edit the text while it is up.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run code.
      Right click on label to open popup menu.
      Click in combo box.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expect the popup menu to close when the combo box is clicked.
      ACTUAL -
      Popup menu stays open.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;


      public class PopupMenuBug {
         public static void main(String[] args) {
            SwingUtilities.invokeLater(
                  new Runnable() {
                     public void run() {
                        JFrame f = new JFrame();
                        JComboBox cb = new JComboBox();
                        cb.setEditable(true);
                        f.getContentPane().add(cb, "North");
                        final JLabel l = new JLabel("Click Here");
                        final JPopupMenu popup = new JPopupMenu();
                        popup.add(new JMenuItem("Test"));
                        
                        l.addMouseListener(
                              new MouseAdapter() {
                                 public void mousePressed(final MouseEvent e) {
                                    if (e.isPopupTrigger()) {
                                       popup.show(l, e.getX(), e.getY());
                                    }
                                 }
                              
                                 public void mouseReleased(final MouseEvent e) {
                                    if (e.isPopupTrigger()) {
                                       popup.show(l, e.getX(), e.getY());
                                    }
                                 }
                              });
                        f.getContentPane().add(l, "Center");
                        f.pack();
                        f.setVisible(true);
                     }
                  });
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Add an AWTEventListener to the toolkit and copy into it some of the machinery of the listener in BasicPopupMenuUI but have it ignore the "doNotCancelPopup" property. This is a poor solution since future changes to the mechanism may break this code. Unfortunately there seems to be no easier way to fix this.

            dnguyen Damon Nguyen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: