JDK-4760494 : 1.4 REGRESSION: JPopupMenu doessn't accept keyboard input(4212563 not fixed)
  • Type: Bug
  • Status: Resolved
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P3
  • Affected Version: 1.4.0
  • OS: windows_2000
  • CPU: x86
  • Submit Date: 2002-10-09
  • Updated Date: 2002-11-16
  • Resolved Date: 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 Availabitlity Release.

To download the current JDK release, click here.
Other
1.4.2 mantisResolved
Description

Name: sv35042			Date: 10/09/2002


FULL PRODUCT VERSION :
java version "1.4.0"
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 :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
  Bug 4214563 is not fixed or has resurfaced in JDK1.4.  Run
the following program.  Right-click anywhere on the frame.
Try using cursor keys, enter, or any of the shortcuts.
Nothing works.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the following code.
2. Right-click mouse on the frame to bring up popup
3. Press the cursor keys.
4. Notice that nothing happens
5. Press enter
6. Notice that nothing happens
7. Press the A key
8. Notice that nothing happens
9. Press ALT-A
10. Notices that nothing happens


EXPECTED VERSUS ACTUAL BEHAVIOR :
I expected the cursor keys to chagne the popup selection.
I expected the shortcuts (mnemonics) to work.  I expected
Enter and ESC to dismiss the popup.

This bug can be reproduced always.

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

public class PopupBug extends JFrame{
  private JPopupMenu popup;
  public PopupBug(){
    super("Popup");
    init();
  }
  private void init(){
    setPopup();
    addMouseListener(new MouseAdapter(){
      public void mousePressed( MouseEvent e ){
        if(e.isPopupTrigger()){
          popup.show(getThis(),e.getX(),e.getY());
        }
      }
      public void mouseClicked( MouseEvent e ){
        if(e.isPopupTrigger()){
          popup.show(getThis(),e.getX(),e.getY());
        }
      }
      public void mouseReleased( MouseEvent e ){
        if(e.isPopupTrigger()){
          popup.show(getThis(),e.getX(),e.getY());
        }
      }
    });
    setSize(400,400);
    setLocation(450,200);
    setVisible(true);
  }
  private void setPopup(){
    popup = new JPopupMenu();
    JMenuItem item;
    popup.add(item=new JMenuItem("Confirm"));
    item.setMnemonic('C');
    popup.add(item=new JMenuItem("Add"));
    item.setMnemonic('A');
    popup.add(item=new JMenuItem("Delete"));
    item.setMnemonic('D');
    popup.add(item=new JMenuItem("Print"));
    item.setMnemonic('P');
    popup.addSeparator();
    popup.add(item=new JMenuItem("Quit"));
    item.setMnemonic('Q');
  }
  private JFrame getThis(){return this;}
  public static void main(String[] args){
    new PopupBug();
  }
}
---------- END SOURCE ----------

Release Regression From : 1.3.1
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: 146174) 
======================================================================

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: azR10139 Date: 11/01/2002 ------- BasicPopupMenuUI.java ------- *** /tmp/sccs.w4aqzu Wed Oct 23 18:40:45 2002 --- BasicPopupMenuUI.java Wed Oct 23 18:31:33 2002 *************** *** 972,984 **** } } else { Component c = popup.getInvoker(); ! while (!(c instanceof JComponent)) { ! if (c == null) { ! return; } ! c = c.getParent(); } - invoker = (JComponent)c; } // remember current focus owner --- 972,990 ---- } } else { Component c = popup.getInvoker(); ! if(c instanceof JFrame) { ! invoker = ((JFrame)c).getRootPane(); ! } else if(c instanceof JApplet) { ! invoker = ((JApplet)c).getRootPane(); ! } else { ! while (!(c instanceof JComponent)) { ! if (c == null) { ! return; ! } ! c = c.getParent(); } ! invoker = (JComponent)c; } } // remember current focus owner ======================================================================
2004-08-24

EVALUATION This has likely been fixed by other fixs, none-the-less we need to verify it has been fixed for mantis. ###@###.### 2002-10-18 Name: azR10139 Date: 11/01/2002 The problem is caused by the incorrect algorithm of search of the appropriate RootPane in BasicRootPane$MenuKeyboardHelper.stateChanged() method. The idea of suggested fix is to check if invoker is instance of JFrame or JApplet and use its RootPane to install keyboard helper which forwards all the key events to the popup. ###@###.### 11/01/2002 ======================================================================
2002-11-01