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

Problems with JPopupMenu and menu origin shift

XMLWordPrintable

      The problem can be easily reproduced using the SwingSet example provided with the Swing 1.0.3 release.
      Here are the steps:

      a) Edit the file SwingSet.java found in the directory: %SWING_HOME%\examples\SwingSet\src
      b) Locate the following statement in the module (should be at or about line 1030):

              addMenuItem(food, "Pizza", pizza);

      c) Immediately after the statement above, add the following statements:

              // ***
              // *** BEGIN JPopupMenu Example ***
              // ***

              // Create mouse listener for triggering popup...
              p.addMouseListener( new MouseAdapter() {
                 public void mouseReleased( MouseEvent e ) {

                    JPopupMenu popup = new JPopupMenu();

                    // Add menu items to popup...
                    popup.add( new JMenuItem( "New..." ) );
                    popup.add( new JMenuItem( "Open..." ) );
                    popup.addSeparator();
                    popup.add( new JMenuItem( "Save" ) );
                    popup.add( new JMenuItem( "Save As..." ) );
                    popup.addSeparator();
                    popup.add( new JMenuItem( "Exit" ) );

                    popup.setLightWeightPopupEnabled( false );
                    popup.show( e.getComponent(), e.getX(), e.getY() );
                 }
              });

              // ***
              // *** END JPopupMenu Example ***
              // ***

      d) Save this change and compile this module using "javac SwingSet.java"
      e) Copy the resulting .class files to the directory: %SWING_HOME%\examples\SwingSet\classes
      f) Change to the directory: %SWING_HOME%\examples\SwingSet
      g) Run the SwingSet application demo by typing "runnit" from the command line.
      h) Once the SwingSet demo has completed initializing, switch to the "Windows Style Look and Feel" located
         under the "Options" pull-down menu.
      i) Click on the Tab labeled "Menus & ToolBars".
      j) Now right click somewhere between the "Menus:" and "ToolBar:" areas to activate the popup menu. You will
         observe a noticeable flash wherein the popup is initially rendered at a location just above and to the
         left of the mouse point; then, the popup's origin is repositioned and re-painted at the correct location
         just under the mouse point.
      k) If you now remove the call to "setLightWeightPopupEnabled( boolean )" in the demo code, recompile, and
         rerun the scenario, no shift of the popup menu occurs.

      merwyn.welcome@eng 1998-09-18

            apikalev Andrey Pikalev
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: