Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8348041

A popup window may close immediately after it appears on Linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 11, 17, 21, 24, 25
    • client-libs
    • None

      A popup window may close immediately after it appears in Linux if a submenu item has been clicked before.

      To reproduce use the attached FocusableNestedMenu.java.
              // To reproduce manually
              // 0. set automated to false and run the test
              // 1. right click on the frame
              // 2. select "sub menu title" submenu
              // 3. click on the item
              // 4. try to open the menu again by right clicking on the frame
              // it will disappear immediately, but if you press the right button and then
              // away from the menu and release the button there, the menu will
              // stay on the screen.

      This only happens on Linux, both X11 and XWayland are affected.
      For some reason the mouseReleased event is passed to the BasicMenuUI handler for a newly opened popup menu, it calls manager.clearSelectedPath(); which causes the popup menu to be dismissed.

      https://github.com/openjdk/jdk/blob/644d154c7c771236904560fc5b91f149a6a646cf/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java#L551

      Applying the following patch solves the issue, and from the testing, nothing seems to be broken, but it should be tested more thoroughly

      --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java
      +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java
      @@ -25,6 +25,7 @@
       
       package javax.swing.plaf.basic;
       
      +import jdk.internal.util.OperatingSystem;
       import sun.swing.DefaultLookup;
       import sun.swing.UIAction;
       import java.awt.*;
      @@ -547,8 +548,9 @@ public void mouseReleased(MouseEvent e) {
                   MenuSelectionManager manager =
                       MenuSelectionManager.defaultManager();
                   manager.processMouseEvent(e);
      - if (!e.isConsumed())
      + if (!e.isConsumed() && !OperatingSystem.isLinux()) {
                       manager.clearSelectedPath();
      + }
               }
       
               /**



            azvegint Alexander Zvegintsev
            azvegint Alexander Zvegintsev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: