<Swing Dev> Issue with setComponentPopupMenu

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Thu Oct 5 16:01:55 UTC 2017


Hello.
Thank you for the report. Could you please create CR for this bug here: 
http://bugreport.java.com/bugreport


On 10/5/17 03:35, Van Den Borre, Koen wrote:
> I forgot to mention that I see this behavior on macOS Sierra 10.12.6 
> (16G29)
> 
> 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)
> 
>> On 5 Oct 2017, at 12:32, Van Den Borre, Koen 
>> <Koen.VanDenBorre at esko.com <mailto:Koen.VanDenBorre at esko.com>> wrote:
>>
>> Hey,
>>
>> 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.
>>
>> 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.
>>
>> As always an example says more that a thousand words:
>>
>> import javax.swing.JDialog;
>> import javax.swing.JFrame;
>> import javax.swing.JLabel;
>> import javax.swing.JMenuItem;
>> import javax.swing.JPopupMenu;
>> 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);
>>
>> JDialog dialog = new JDialog(frame, "Modeless Dialog", false);
>> dialog.getContentPane().add(new JLabel("Do a contextual mouse click 
>> here"));
>> dialog.setSize(300, 300);
>> dialog.setLocation(50, 50);
>> dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
>> dialog.setVisible(true);
>> }
>> }
>>
>>
>> Please be advised that this email may contain confidential 
>> information. If you are not the intended recipient, please notify us 
>> by email by replying to the sender and delete this message. The sender 
>> disclaims that the content of this email constitutes an offer to enter 
>> into, or the acceptance of, any agreement; provided that the foregoing 
>> does not invalidate the binding effect of any digital or other 
>> electronic reproduction of a manual signature that is included in any 
>> attachment.
> 
> Please be advised that this email may contain confidential information. 
> If you are not the intended recipient, please notify us by email by 
> replying to the sender and delete this message. The sender disclaims 
> that the content of this email constitutes an offer to enter into, or 
> the acceptance of, any agreement; provided that the foregoing does not 
> invalidate the binding effect of any digital or other electronic 
> reproduction of a manual signature that is included in any attachment.


-- 
Best regards, Sergey.



More information about the swing-dev mailing list