JDK-6495511 : Cascading popups broken in 1.6
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-11-20
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u2Fixed 7 b15Fixed
Related Reports
Relates :  
Relates :  
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 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
26-03-2007

EVALUATION see also workaround section
08-12-2006

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

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