JDK-6421284 : JPopupMenu behaves incorrectly with invoker being set to null
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2006-05-03
  • Updated: 2011-01-19
  • Resolved: 2007-04-03
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.
6 b92Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Run the following test (it is also attached to the bug report):


import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class NullInvoker
  public static void main(String[] args)
    final JFrame f = new JFrame("F");
    f.setBounds(100, 100, 100, 100);
    JButton b = new JButton("B");
    b.addActionListener(new ActionListener()
      public void actionPerformed(ActionEvent e)
        JPopupMenu p = new JPopupMenu();
        p.add(new JMenuItem("Item1"));
        p.add(new JMenuItem("Item2"));
        p.add(new JMenuItem("Item3"));
        // uncomment the next line to fix the problem
//        p.setInvoker(f);
        p.setLocation(300, 300);


When the test starts a frame with a button is shown. Click on the button to show JPopupMenu. It is not clickable and doesn't track any mouse move events to selected the proper menu item. After any item is clicked, popup is not closed.

EVALUATION This fix was rolledback see 6495511

EVALUATION isPopupMenu() method used to return false for the null invoker, that's was the reason of incorrect selection behaviour, see JPopupMenu.setVisible() method (if it is not isPopupMenu() we don't set any initial selection) It also caused a problem when you click to the menu and it didn't hide, because JPopupMenu.menuSelectionChanged() hide the menu only if isPopupMenu returns true

EVALUATION The problem appeared when we tried to add JPopupMenu to TrayIcon since no invoker was initially set, JPopupMenu behaviours really strange it was impossible to highlight or select any ot its menuItems Test case in the bug's description shows the same behaviour, setting invoker to any non-null Component fixes the problem Need to fix JPopupMenu.isPopupMenu() method

EVALUATION We just need to fix it

WORK AROUND I think the previous comment meant to say something like "this will be probably fixed with an upcoming Swing fix (6400183)", referring to a bug fix where Swing is fixing the problem with the autoshutdown now working. This is correct. However, we should still support JPopupMenu with a null invoker.

WORK AROUND Setting any not-null value for invoker (see commented line in the test) fixes the problem. However, this leads to another problem: popup frame is not disposed and that prevents the whole Java application from autoshutdown (this will be probably fixed with