JDK-4694797 : 1.4 REGRESSION: Incorrect focussing after using JPopupMenu.setVisible(false)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,windows_2000
  • CPU: x86
  • Submitted: 2002-05-31
  • Updated: 2002-11-16
  • Resolved: 2002-11-16
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.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 05/30/2002


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Windows NT 4.00.1381

ADDITIONAL OPERATING SYSTEMS :
Linux

A DESCRIPTION OF THE PROBLEM :
I have included a small piece of code below that I am using.

I basically want to add a small component of my own (represented by the closePopup button)
to a JPopupMenu. When I finish performing operations on my component I want to close the popup
menu, which I am doing using the setVisible(false) method to hide the popup menu

However in I get a problem, when I click on any other button
in the Frame the event is not actionPerformed event is not thrown
for that click. Only when it is clicked for the second time
is the event thrown

See Forum Thread 249053


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the above code
2. Click on the "Show Popup" button
3. Click the "Close popup" button in the menu
4. Click the "Test" button (A message box should appear)
5. Click on the "Test" button again. Now the message box appears.


EXPECTED VERSUS ACTUAL BEHAVIOR :
The Message Dialog should appear on the first click of the "Test" button

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
 *
 * @author  grantl
 */
public class PopupTest extends JFrame implements ActionListener {

    private JButton showPopup, closePopup, test;
    private JPopupMenu popup;
    /** Creates a new instance of PopupTest */
    public PopupTest() {
        super();
        init();
        setVisible(true);
    }
    
    public void init() {
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        getContentPane().setLayout(new GridLayout(3,1));
        getContentPane().add(new JLabel("Test Label"));
        getContentPane().add(test = new JButton("Test"));
        getContentPane().add(showPopup = new JButton("Show popup"));
        closePopup = new JButton("Close popup");
        test.addActionListener(this);
        showPopup.addActionListener(this);
        closePopup.addActionListener(this);
        popup = new JPopupMenu();
        popup.add(closePopup);
        pack();
    }
    
    public void actionPerformed(ActionEvent ae) {
        if (ae.getSource().equals(showPopup)) {
            Dimension d = showPopup.getSize();
            popup.show(showPopup, 0, d.height);
        }
        else if (ae.getSource().equals(closePopup)) {
            popup.setVisible(false);
        }
        else {
            JOptionPane.showMessageDialog(this, "Test");
        }
    }
    
    public static void main(String args[]) {
        new PopupTest();
    }
    
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 146023) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b08
2004-08-24

SUGGESTED FIX Name: pzR10082 Date: 10/25/2002 *** /net/diablo/export2/swing/zpm/webrev/src/share/classes/javax/swing/MenuSelectionManager.java- Fri Oct 25 12:15:21 2002 --- MenuSelectionManager.java Fri Oct 25 12:12:21 2002 *************** *** 72,85 **** } for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) { ! ((MenuElement)selection.elementAt(i)).menuSelectionChanged(false); selection.removeElementAt(i); } for(i = firstDifference, c = path.length ; i < c ; i++) { if (path[i] != null) { - path[i].menuSelectionChanged(true); selection.addElement(path[i]); } } --- 72,86 ---- } for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) { ! MenuElement me = (MenuElement)selection.elementAt(i); selection.removeElementAt(i); + me.menuSelectionChanged(false); } for(i = firstDifference, c = path.length ; i < c ; i++) { if (path[i] != null) { selection.addElement(path[i]); + path[i].menuSelectionChanged(true); } } *************** *** 104,110 **** * when a choice has been made */ public void clearSelectedPath() { ! setSelectedPath(null); } /** --- 105,113 ---- * when a choice has been made */ public void clearSelectedPath() { ! if (selection.size() > 0) { ! setSelectedPath(null); ! } } /** *** /net/diablo/export2/swing/zpm/webrev/src/share/classes/javax/swing/JPopupMenu.java- Fri Oct 25 12:15:20 2002 --- JPopupMenu.java Fri Oct 25 12:13:37 2002 *************** *** 762,767 **** --- 762,772 ---- popup.hide(); popup = null; firePropertyChange("visible", Boolean.TRUE, Boolean.FALSE); + // 4694797: When popup menu is made invisible, selected path + // should be cleared + if (isPopupMenu()) { + MenuSelectionManager.defaultManager().clearSelectedPath(); + } } if (accessibleContext != null) { if (b) { ###@###.### 2002-10-25 ======================================================================
2002-10-25

EVALUATION I verified this is indeed a regression in 1.4.X. Since having an unresponsive button is an extremely bad usability problem, I would recommend we consider fixing this for mantis if the fix isn't too risky. ###@###.### 2002-10-18 Name: pzR10082 Date: 10/25/2002 When JPopupMenu.setVisible(false) is called, menu selection should be cleared. However, a number of minor problems should be solved beforehand: * MenuSelectionManager.setSelectedPath() calls menuSelectionChanged() before the selection has actually changed. If a menu element examines the selection at this moment, it will see it in an inconsistent state. * JPopupMenu.setVisible(false) should call MenuSelectionManager.clearSelectedPath(), so that when a popup menu is hidden, menu selection is cleared. However, clearSelectedPath() can hide popup menu when, for example, menu is being canceled. clearSelectedPath() should be made a no-op if the selection is already empty. This is so that clearSelectedPath() is not reentered: reentering clearSelectedPath() causes an exception. ###@###.### 2002-10-25 ======================================================================
2002-10-25