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

JPopupMenu does not display if invoker is instance of JWindow

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b21
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Not verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0"
        Java(TM) SE Runtime Environment (build 1.6.0-b105)
        Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        A call to JPopupMenu.show(Component invoker, int x, int y) will fail to show the JPopupMenu if the invoker passed in is a JWindow. A call to the JPopupMenu "isVisible()" method will return true, but the popup menu will not actually be displayed.

        This problem does not occur with JDK 1.5.0_11.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        The source code provided in "Source code for an executable test case" will reproduce the problem. Compile and run, then right click in the gray window which appears in the upper left hand corner of the screen.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The test program program should display a popup menu with a single menu option called "quit". The following message (or similar) should be displayed on stdout:

        Showing menu at java.awt.Point[x=71,y=76] isVisible: true isValid: true

        ACTUAL -
        No popup is displayed. The message printed out on stdout shows that the "isVisible" method on the popup menu is returning true, and that the location of the menu is right in the middle of the box, where it should be:

        Showing menu at java.awt.Point[x=74,y=86] isVisible: true isValid: true


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.Point;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.MouseAdapter;
        import java.awt.event.MouseEvent;
        import javax.swing.JMenuItem;
        import javax.swing.JPopupMenu;
        import javax.swing.JWindow;

        public class Main {
          
          /** Creates a new instance of Main */
          public Main() {
          }
          
          /**
           * Mouse adapter which listens for mouse events and shows a popup menu as
           * required.
           */
          static public class PopupListener extends MouseAdapter {
            JPopupMenu menu;

            public PopupListener(
              JPopupMenu menu
            ) {
              this.menu = menu;
            }
            
            public void mousePressed(MouseEvent e) {showPopup(e);}
            public void mouseReleased(MouseEvent e) {showPopup(e);}
            private void showPopup(MouseEvent e) {
              if(e.isPopupTrigger()) {
                // This doesnt' work if e.getComponent() is a JWindow
                menu.show(e.getComponent(), e.getX(), e.getY());
                
                System.out.println(
                  "Showing menu at " + menu.getLocationOnScreen() +
                  " isVisible: " + menu.isVisible() +
                  " isValid: " + menu.isValid());
              }
            }
          }

          
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
            JWindow window = new JWindow();
            window.setBounds(10, 10, 100, 100);
            
            JPopupMenu popupMenu = new JPopupMenu();
            JMenuItem quit = new JMenuItem("Quit");
            quit.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                System.exit(0);
              }
            });
            popupMenu.add(quit);
            
            window.addMouseListener(new PopupListener(popupMenu));
            
            window.setFocusable(true);
            
            window.validate();
            window.setVisible(true);
          }
          
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Instead of calling JPopupMenu.show() and passing the JWindow:

        private void showPopup(MouseEvent e) {
          Point componentLocation = e.getComponent().getLocationOnScreen();
          menu.show(null, componentLocation.x + e.getX(), componentLocation.y + e.getY());
        }

        Release Regression From : 5.0u9
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                son Oleg Sukhodolsky (Inactive)
                Reporter:
                keshah Ketan Shah (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: