JDK-8189253 : JPopupMenu is inadvertently shown when using setComponentPopupMenu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u112,9,10,11,12,13
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2017-10-10
  • Updated: 2019-04-16
  • Resolved: 2019-04-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 Availability Release.

To download the current JDK release, click here.
JDK 13
13Resolved
Related Reports
Cloners :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_152-ea"
Java(TM) SE Runtime Environment (build 1.8.0_152-ea-b05)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b05, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

macOS Sierra 10.12.6 (16G29)

A DESCRIPTION OF THE PROBLEM :
I am seeing an issue when using setComponentPopupMenu.

When you use setComponentPopupMenu in a window and create a modeless dialog and position that over that window. A contextual menu click in the modeless dialog will show the contextual men of the component in the parent window when that parent window has the focus.

I traced the issue down to processMouseEvent in the Container class. There, a call is made to trackMouseEnterExit which will create and dispatch a MouseEvent.MOUSE_ENTERED mouse event.

This generated mouse event still has the isPopupTrigger attribute set to true which will then triggers the componentPopupMenu to be shown.

REGRESSION.  Last worked in version 8u121

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Run the test program
- Want until the modeless dialog is shown on top of the main frame.
- Make sure the main frame has the focus
- Do a contextual menu click inside the modeless dialog.
- The JPopupMenu that was installed on the main frame's root pane is shown

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JPopupMenu that was installed on the main frame's root pane should not be shown
ACTUAL -
The JPopupMenu that was installed on the main frame's root pane is shown

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class ComponentPopupMenuTest {
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				test();
			}
		});
	}

	private static void test() {
		JPopupMenu popupMenu = new JPopupMenu();
		popupMenu.add(new JMenuItem("You should not see me"));

		JFrame frame = new JFrame("Main Frame");
		frame.getRootPane().setComponentPopupMenu(popupMenu);
		frame.setSize(400, 400);
		frame.setLocation(0, 0);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);

		JTextArea info = new JTextArea("Do a contextual mouse click here while the Main Frame is active");
		info.setWrapStyleWord(true);
		info.setLineWrap(true);

		JDialog dialog = new JDialog(frame, "Modeless Dialog", false);
		dialog.getContentPane().add(info);
		dialog.setSize(300, 300);
		dialog.setLocation(50, 50);
		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		dialog.setVisible(true);

		frame.toFront();
	}
}

---------- END SOURCE ----------


Comments
The problem was triggered by JDK-8080729 which introduced windows ordering. In particular the root cause of this one is ���double ordering issue���, (i.e. orderFront() is called for the focused window which is already located above other windows). The issue was addressed by JDK-8213983 So closing this one as dupe.
16-04-2019

[~dmarkov] since this issue is related to JDK-8080729 as it seems it goes away as mentioned by Manajit, if that fix is taken out, can you in your spare time take a look at this issue? Thx in advance.
01-04-2019

[~psadhukhan] Sure, I will look into this but a little bit later. Currently I am busy with some other tasks. You can assign this one to me so I won't forget
01-04-2019

It seems when the mouse is "dragged" from parent window to modeless dialog by pressing the left button and then immediately pressing the right button, when mouse moves to modeless dialog, the issue of popup being shown is present in linux and mac even in 8GA so that behaviour is not a regression. However, if mouse right button is "clicked" in modeless dialog when parent window has focus, then popup getting shown issue is not present in mac in 8GA but present in 11, so that behaviour is regression. This "click" issue is not present in linux in 11.
25-04-2018

I have tested on ubuntu 16.04. The issue described in the review thread that "when mouse is dragged to another component with the left button pressed and then the right button is immediately pressed. The popup is triggered by the same logic despite it isn't configured for the component". Note, the popup is shown only momentarily and not kept shown as it is mac. Also, it is present in jdk8GA too and not a regression, so the issue seen on linux is a bit different than it is on mac. So, I have created a separate issue for linux and needs to be handled differently. For mac, I am reassigning to Manajit to confirm if it is a regression of JDK-8080729 or not.
25-04-2018

Victor, acording to the discussion on Swing-dev mailing list the problem is also reproducible on linux. So it is NOT a regression of JDK-8080729. Please find more details here: http://mail.openjdk.java.net/pipermail/swing-dev/2017-December/008077.html http://mail.openjdk.java.net/pipermail/swing-dev/2018-January/008114.html
09-04-2018

Dmitry, can you take care about this regression issue fix? (caused by JDK-8080729) ?
09-04-2018

Issue reproduced on macOS Sierra 10.12.6 with JDK 9GA build.
31-10-2017

According to description using setComponentPopupMenu in a window with a modeless dialog positioned over that, a contextual menu click in the modeless dialog will show the contextual menu of the component in the parent window when that parent window has the focus. This seems a regression introduced in JDK 8u112. Confirmed this with attached test case and confirmed that the issue does exist in JDK 8u152 as well as 9 and JDK 10 ea b26. See attached image for reference. Results: 7u80 -OK 8u20 - OK 8u60 - OK 8u92 - OK 8u102 - OK 8u111 - OK 8u112 - FAIL 8u121 - FAIL 8u131 - FAIL 8u144 - FAIL 8u152 b16 - FAIL 9 GA - FAIL 9.0.1 b11 - FAIL 10 ea b26 - FAIL To verify run the attached test case with respective JDK versions.
13-10-2017