Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6421284
Votes 0
Synopsis JPopupMenu behaves incorrectly with invoker being set to null
Category java:classes_swing
Reported Against
Release Fixed mustang(b92)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 6285881 , 6400183 , 6495511 , 2148120 , 6192557
Submit Date 03-MAY-2006
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.
Posted Date : 2006-05-03 15:39:15.0
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
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.
Evaluation
We just need to fix it
Posted Date : 2006-06-28 12:47:09.0

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
Posted Date : 2006-07-04 15:22:18.0

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
Posted Date : 2006-07-12 15:59:38.0

This fix was rolledback
see 6495511
Posted Date : 2007-03-29 15:46:58.0
Comments
  
  Include a link with my name & email   

Submitted On 27-OCT-2006
Binh_Truong
JPopupMenu cannot associate with TrayIcon. When I use TrayIcon and use JPopupMenu then I only close this popup when click on its menuitem  but when I use PopupMenu with TrayIcon the very good.



PLEASE NOTE: JDK6 is formerly known as Project Mustang