JDK-8270322 : JPopupMenu is blocked when opened in a modal Dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,11,16,17
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-07-04
  • Updated: 2022-08-01
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.
Other
tbdUnresolved
Description
ADDITIONAL SYSTEM INFORMATION :
java -version: 
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-24)
OpenJDK 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

Windows:
Windows 10 Pro for Workstations 20H2
19042.1052


A DESCRIPTION OF THE PROBLEM :
When a JPopupMenu is displayed as a reaction to a user interaction in a modal dialog, the user can not interact with any components inside the JPopupMenu - It seems to be blocked because of the Dialog being modal. This is independent from allwing/disabling lightweight popups

The same works flawlessly in Linux (Ubuntu 20.04)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached class, click on the action and try to click any button in the resulting JPopupMenu:


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should be possible to interact with components in a JPopupMenu opened inside a modal Dialog
ACTUAL -
It is not possible to interact with components in the JPopupMenu  opened inside a modal Dialog

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.ActionEvent;

public class PopUpAction extends javax.swing.AbstractAction implements
java.awt.event.WindowFocusListener
,java.awt.event.ActionListener
{
	private static final int POPUPOFFSET=5;
	private javax.swing.JToolBar toolbar=new javax.swing.JToolBar();
	private javax.swing.JPopupMenu pmenu;
	private java.util.List<javax.swing.Action> actions;

	public PopUpAction()
	{
		super();
		init();
	}
	public PopUpAction(java.lang.String name)
	{
		super(name);
		init();
	}
	public PopUpAction(java.lang.String name, javax.swing.Icon icon)
	{
		super(name,icon);
		init();
	}
	private void init()
	{
		actions=new java.util.LinkedList();
		pmenu=new javax.swing.JPopupMenu();
		pmenu.setLightWeightPopupEnabled(false);
	}
	public javax.swing.AbstractButton add(javax.swing.Action action)
	{
		actions.add(action);
		javax.swing.AbstractButton btn=null;
		if(action.getValue(javax.swing.Action.SELECTED_KEY)!=null)
		{
			javax.swing.JToggleButton jtb=new javax.swing.JToggleButton(action);
			if(action.getValue(javax.swing.Action.SELECTED_KEY)!=null)
			{
				jtb.setSelectedIcon((javax.swing.Icon)action.getValue("SELECTED_ICON"));
			}
			btn=jtb;
			toolbar.add(jtb);
		}
		else
			btn=toolbar.add(action);
		pmenu.add(btn);
		btn.addActionListener(this);
		return btn;
	}
	public void setOrientation(int o)
	{
		if(pmenu!=null)
			pmenu.setVisible(false);
		toolbar.setOrientation(o);
	}
	public void windowGainedFocus(java.awt.event.WindowEvent e)
	{
	}
	public void windowLostFocus(java.awt.event.WindowEvent e)
	{
		if(pmenu!=null)
			pmenu.setVisible(false);
	}
	public void actionPerformed(java.awt.event.ActionEvent evt)
	{
		java.lang.Object source=evt.getSource();
		if(pmenu.isVisible()==true)
			pmenu.setVisible(false);
		else
		{
			try{
			java.awt.Component c=(java.awt.Component)evt.getSource();
			if(toolbar.getOrientation()==javax.swing.SwingConstants.VERTICAL)
			{
				pmenu.setLocation((int)(c.getLocationOnScreen().getX())+POPUPOFFSET,(int)(c.getLocationOnScreen().getY()+c.getHeight())-POPUPOFFSET);//,dialog.getWidth(),dialog.getHeight());
			}
			else
			{
				pmenu.setLocation((int)(c.getLocationOnScreen().getX()+c.getWidth())-POPUPOFFSET,(int)(c.getLocationOnScreen().getY())+POPUPOFFSET);//,dialog.getWidth(),dialog.getHeight());
			}
			pmenu.setVisible(true);
			pmenu.requestFocusInWindow();
			}
			catch(java.awt.IllegalComponentStateException exp){}
		}
	}
	public void clear()
	{
		actions.clear();
		toolbar.removeAll();
	}

	public boolean isPopupVisible()
	{
		return pmenu.isVisible();
	}

	public static void main(java.lang.String[] args)
	{
		java.awt.Dialog dialog=new javax.swing.JDialog((java.awt.Frame)null,"title",true);
		javax.swing.JPanel p=new javax.swing.JPanel(new java.awt.BorderLayout());
		javax.swing.JToolBar tb=new javax.swing.JToolBar();
		tb.setFloatable(false);
		p.add(tb, BorderLayout.NORTH);
		PopUpAction popUpAction=new PopUpAction("tata");
		popUpAction.add(new javax.swing.AbstractAction("huhu")
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{

			}
		});
		popUpAction.add(new javax.swing.AbstractAction("hallo")
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{

			}
		});

		tb.add(popUpAction);
		dialog.add(p);
		dialog.pack();
		dialog.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
There is none known

FREQUENCY : always



Comments
Observation is seen only in Windows OS, whereas in Ubuntu the observation is not reproducible. Pop up is not blocked if replaced with JFrame, suspecting it to be a property of Windows OS where Dialogue blocks the other popup until its closed.
12-07-2022

Checked with attached testcase in Windows 10, Issue is reproducible, not able to select JPopupMenu, Test Result: ========= 8: Fail 8u291: Fail 11: Fail 11.0.11: Fail 16: Fail 17ea30: Fail when the executing the same testcase in Ubuntu 20.04, issue could not be reproduced, was able to select JPopupMenu Test Result: ======== 8u291: Pass 11.0.11 Pass 16: Pass 17ea30 Pass
12-07-2021