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

Removing JComboBox during popupMenuWillBecomeVisible orphans popup

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"


      A DESCRIPTION OF THE PROBLEM :
      during JComboBoxes firing of popupWillBecomeVisible, if the JComboBox is removed from its parent the popup becomes orphaned. JComboBox does have code to deal with its removal and the popup but at this point in the notification it has not effect. What is occuring:

      setVisible(true) is called.
      1. This first works with the MenuSelectionManger to set up the popup part in the selected path.
      2. Notification occurs that the popup will become visible.
      3. The JComboBox is removed. This causes the MenuSelectionManager's path to be cleared.
      4. Notification is over, the popup is made visible.

      At this point clicking on it/selecting an item causes the hide functionality to execute. This checks the selected path, but since the selected path no longer contains the popup it does nothing. See BasicComboPopup's hide method for details on this.

      The JComboBox's popup is 'orphaned' at this point.


      Also note that
      http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5078557
      manifests this problem, though fixing this bug does not really fix the problem(s) of that one.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run this code, try selecting an item in the JComboBoxes popup:
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.event.*;

      public class TestJComboBox implements Runnable, PopupMenuListener{

          JComboBox jcb;
          public void run(){
              Object[] data = new Object[]{ "1", "2","3","4" };
              jcb = new JComboBox(data);
              jcb.addPopupMenuListener(this);
              JFrame jf = new JFrame();
              jf.add(jcb);
              jf.pack();
              jf.setLocationRelativeTo(null);
              jf.setVisible(true);

          }

          public void popupMenuWillBecomeVisible(PopupMenuEvent e){
              jcb.getParent().remove(jcb);
          }
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e){}
          public void popupMenuCanceled(PopupMenuEvent e){}

          public static void main(String ... args){
              SwingUtilities.invokeLater(new TestJComboBox());
          }

      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the popup to go away when the JComboBox is removed
      ACTUAL -
      its still there, orphaned

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class TestJComboBox implements Runnable, PopupMenuListener{

          JComboBox jcb;
          public void run(){
              Object[] data = new Object[]{ "1", "2","3","4" };
              jcb = new JComboBox(data);
              jcb.addPopupMenuListener(this);
              JFrame jf = new JFrame();
              jf.add(jcb);
              jf.pack();
              jf.setLocationRelativeTo(null);
              jf.setVisible(true);

          }

          public void popupMenuWillBecomeVisible(PopupMenuEvent e){
              jcb.getParent().remove(jcb);
          }
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e){}
          public void popupMenuCanceled(PopupMenuEvent e){}

          public static void main(String ... args){
              SwingUtilities.invokeLater(new TestJComboBox());
          }

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

      CUSTOMER SUBMITTED WORKAROUND :
      unknown, uncertain if popup can be retrieved and removed.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: