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

Wrong menu selection in applet

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6u12
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_12"
      Java(TM) SE Runtime Environment (built 1.6.0_12-b04)
      Java HotSpot(TM) Client VM (built 11.2-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Red Hat Enterprise Linux 5.0 Gnome metacity 2.16
      openSUSE 10.3 KDE 3.5.7

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Firefox 2.0,
      JRE 1.6u12

      A DESCRIPTION OF THE PROBLEM :
      When running an applet with a menu with JRE1.6 clicking on the first level menus causes wrong selection of menu items in its popup. In case the user clicks more frequently it might even cause the item to be clicked (even the cursor is still above the first level menu!).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Start applet
      - Maximize browser window
      - Click on 'menu1' or 'menu2' several times slowly
          --> item in popup will be selected even the mouse cursor is still above the menu
      - Switching between 'menu1' and 'menu2' faster
          --> selected item will be activated (see system out) even the mouse cursor is still above the menu

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Selection and activation should only be triggered by item below cursor position

      This behaviour is caused by wrong mouse event position and source that cause wrong position to be calculated when transforming coordinates to screen coordinates.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package gui.applet.file.menu;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JApplet;
      import javax.swing.JButton;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;

      public class MenuApplet extends JApplet
      {
          public MenuApplet()
          {
              super();
              
              JMenuBar menubar = new JMenuBar();
              ActionListener l = new MenuActionListener();
              
              //menu1
              JMenu menu1 = new JMenu("menu1");
              addMenuItems(menu1, l, 12);
              
              //menu2
              JMenu menu2 = new JMenu("menu2");
              addMenuItems(menu2, l, 8);
              
              //menubar.add(Box.createGlue());
              menubar.add(menu1);
              menubar.add(menu2);
              this.getRootPane().setJMenuBar(menubar);

              this.getContentPane().add(new JButton("Focused Button"));
          }
          
          private static void addMenuItems(JMenu menu, ActionListener l, int numItems)
          {
              JMenuItem item;
              String name = menu.getText();
              
              for(int i = 1; i <= numItems; i++)
              {
                  item = new JMenuItem(name + "." + i);
                  item.addActionListener(l);
                  menu.add(item);
              }
          }
          
          private class MenuActionListener implements ActionListener
          {
              public void actionPerformed(ActionEvent e)
              {
                  JMenuItem item = (JMenuItem)e.getSource();
                  System.out.println("#### Menu item clicked: " + item.getText());
              }
          } //END MenuActionListener
      }

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

        Attachments

          Activity

            People

            Assignee:
            serb Sergey Bylokhov
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: