JDK-4706304 : REGRESSION: JPopupMenu doesn't highlight selection on initial click
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-06-21
  • Updated: 2008-11-17
  • Resolved: 2008-11-17
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 7
7Resolved
Related Reports
Relates :  
Relates :  
Description
Name: jk109818			Date: 06/21/2002


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
[Version 5.00.2195] Service Pack 2


A DESCRIPTION OF THE PROBLEM :
Displaying a JPopupMenu with a left mouse click so that the
mouse position resides within the popup may result in a
wrong selection of the popup item. If the popup does at
least partially overlap with the border of a JFrame, the
item under the mouse is selected correctly with the
selection color. If the popup does reside fully inside the
JFrame, the first item is selected, even when the mouse is
on another item when clicked.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile/start code/class TestJPopupMenu
2. Click somewhere in the middle without moving the mouse
after the click.
3. Note the position of the mouse relative to the popup. Is
the popup over another than the first item? Which item is
selected?
4. Do step 2 and 3 but click near the border of the frame.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Result of step 3 is that the selected item is always the
first one, not taking the mouse position into account.

Result of step 4 is that the correct item is selected.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class TestJPopupBug extends javax.swing.JFrame {
	private JPopupMenu popup = new JPopupMenu("Test");
	private int size = 600;
	public TestJPopupBug() {
		popup.add("Level01");
		popup.add("Level02");
		popup.add("Level03");
		popup.add("Level04");
		popup.add("Level05");
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		} );
		this.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				popup.show(TestJPopupBug.this,
					e.getX() - (int)(70 * Math.random()),
					e.getY() - (int)(100 * Math.random()));
			}
		} );
		this.setSize(size, size);
		this.setVisible(true);
	}
	public static void main(String[] s) {
		new TestJPopupBug();
	}
}
---------- 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: 153845) 
======================================================================

Comments
EVALUATION With the latest fixes for JDK 1.6, the first item is not selected by default, see the following blog for more details: http://weblogs.java.net/blog/alexfromsun/archive/2008/02/jtrayicon_updat.html this bug is outdated, closed as not reproducible
17-11-2008

SUGGESTED FIX http://sa.sfbay.sun.com/projects/swing_data/mustang/4706304.2 ###@###.### 2005-04-05 15:41:37 GMT
05-04-2005

EVALUATION Name: azR10139 Date: 10/02/2002 This problem with this bug is that user calls Popup.show() and after that no mouse events happened, so we are unable to find out current mouse position to select menu element that lies under mouse cursor. Commiting this bug to tiger because i unable to fix it until RFE 4009555 will not be integrated. ====================================================================== We can generate MOUSE_MOVED event using current mouse coordinates in JPopupMenu.setVisible() method. After processing this event the menu item mouse is over should be selected. ###@###.### 2005-04-05 15:41:37 GMT
05-04-2005