JDK-2148155 : JPopupMenu behaves incorrectly with invoker being set to null
  • Type: Backport
  • Backport of: JDK-6421284
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P2
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2007-04-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.
JDK 6
6Fixed
Description
Run the following test (it is also attached to the bug report):

---- BEGIN OF SOURCE CODE ----

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);
        p.setVisible(true);
      }
    });
    f.add(b);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setVisible(true);
  }
}

---- END OF SOURCE CODE ----

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.

Comments
EVALUATION The goal of the fix for the 6421284 was to make JPopupMenu works with TrayIcon but - it doesn't solve all problems with TrayIcon - there is a clear workaround how to work with PopupMenus with null invoker (popupMenu.setInvoker(popupMenu)) - it leads to the serious regression 6495511 That's why this bug is closed as will not fix and the previous fix is rolled back
03-04-2007