United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6495511 Cascading popups broken in 1.6
JDK-6495511 : Cascading popups broken in 1.6

Details
Type:
Bug
Submit Date:
2006-11-20
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
In java 1.5.0_09 when one popup is open and contains a button that triggers a second sub popup, when the second popup was triggered the first one remains open.
In 1.6.0 however opening the second popup results in the first one being removed.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile an run the following code with both 1.5 and 1.6 JREs.

Click on the main button, the first  popup will appear.
Click on the button in the first popup.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected both popups to be visible after clicking on the button in the first poup.
ACTUAL -
When the second popup is opened, the first one is removed. This appears to be a regression from the 1.5 behaviour.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.MouseInfo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;

public class CascadingPopups extends JFrame {

    private JPopupMenu popup = null;

    JComboBox dropDown = null;

    private JPopupMenu popup2;

    private JButton popup1Button;

    private JButton mainButton;

    public CascadingPopups() {

        // Create and set up the window.
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(100, 100, 640, 480);
        mainButton = new JButton("Button");
        this.getContentPane().add(mainButton);

        // create the popups
        popup = new JPopupMenu();
        popup.setLayout(new BoxLayout(popup, BoxLayout.Y_AXIS));
        popup.add(new JLabel("Popup 1"));
        popup1Button = new JButton("Button");
        popup.add(popup1Button);

        popup2 = new JPopupMenu();
        popup2.add(new JLabel("Popup 2"));

        mainButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                popup.setLocation(MouseInfo.getPointerInfo().getLocation().x,
                        MouseInfo.getPointerInfo().getLocation().y);
                popup.setVisible(true);
            }
        });
        
        popup1Button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                popup2.setInvoker(popup1Button);
                popup2.setLocation(MouseInfo.getPointerInfo().getLocation().x,
                        MouseInfo.getPointerInfo().getLocation().y);
                popup2.setVisible(true);
            }
        });
        
        // Display the window.
        this.validate();
        this.setVisible(true);
    }

    public static void main(String[] args) {

        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new CascadingPopups();
            }
        });
    }
}

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

Release Regression From : 5.0u9
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

This is a regression of 6421284,
isPopupMenu() returns true for menus with null invoker
and JPopupMenu.menuSelectionChanged() closes the first popup
                                     
2006-12-06
EVALUATION

see also workaround section
                                     
2006-12-08
WORK AROUND

popup.setInvoker(new JMenu());
will fix the problem
                                     
2006-12-08
EVALUATION

It turned out that the fix for 6421284 
doesn't solve all problems with JPopupMenu and TrayIcon, 
so it doesn't make much sense and causes this regression

fix for 6421284 should be rolled back
                                     
2007-03-26



Hardware and Software, Engineered to Work Together