United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6454037 : Removing JComboBox during popupMenuWillBecomeVisible orphans popup

Details
Type:
Bug
Submit Date:
2006-07-28
Status:
Open
Updated Date:
2013-05-17
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
solaris_10
Sub-Component:
javax.swing
CPU:
sparc
Priority:
P4
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:

Related Reports
Relates:

Sub Tasks

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.

                                    

Comments
EVALUATION

Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=14497
                                     
2006-07-29



Hardware and Software, Engineered to Work Together