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

REGRESSION: Selected item is not being updated while dragging above popup menu

XMLWordPrintable

    • b86
    • x86
    • linux

      If you are showing popup on mouse press and continue drag w/o releasing mouse button,
      then menu item under mouse is not selected.

      Here is a test to reproduce the problem:

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class SwingMenus {
          static JFrame frame;
          static JButton button;
          static JPopupMenu menu;
          static class Listener extends MouseAdapter {
              public void mousePressed(MouseEvent e) {
                  if (e.isPopupTrigger()) {
                      menu.show(button, e.getX(), e.getY());
                  }
              }

              public void mouseReleased(MouseEvent e) {
                  if (e.isPopupTrigger()) {
                      menu.show(button, e.getX(), e.getY());
                  }
              }
          }
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable()
                  {
                      public void run() {
                          frame = new JFrame("test frame");
                          button = new JButton("test button");
                          menu = new JPopupMenu("test menu");
                          menu.add(new JMenuItem("item 1"));
                          menu.add(new JMenuItem("item 2"));
                          JMenu submenu1 = new JMenu("submenu 1");
                          menu.add(submenu1);
                          submenu1.add(new JMenuItem("item 1.1"));
                          submenu1.add(new JMenuItem("item 1.2"));
                          JMenu submenu2 = new JMenu("submenu 2");
                          menu.add(submenu2);
                          submenu2.add(new JMenuItem("item 2.1"));
                          submenu2.add(new JMenuItem("item 2.2"));
                          JMenu submenu21 = new JMenu("submenu 2");
                          submenu2.add(submenu21);
                          submenu21.add(new JMenuItem("item 2.1"));
                          submenu21.add(new JMenuItem("item 2.2"));
                          menu.add(new JSeparator());
                          menu.add(new JMenuItem("item 3"));
                          menu.add(new JMenuItem("item 4"));
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.setSize(200, 200);
                          frame.add(menu);
                          frame.add(button);
                          button.addMouseListener(new Listener());
                          frame.setVisible(true);
                      }
                  });
          }
      }
      I cannot reproduce the bug in 1.5.0_06.
      I can reproduce it in 1.6b65, but only with modified test case:

      ---- Begin of source ---
      import java.awt.event.*;
      import javax.swing.*;

      public class SwingMenus {
          static JFrame frame;
          static JButton button;
          static JPopupMenu menu;

          static class Listener extends MouseAdapter {
              public void mousePressed(MouseEvent e) {
                  menu.show(button, e.getX(), e.getY());
              }

              public void mouseReleased(MouseEvent e) {
              }
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      frame = new JFrame("test frame");
                      button = new JButton("test button");
                      menu = new JPopupMenu("test menu");
                      menu.add(new JMenuItem("item 1"));
                      menu.add(new JMenuItem("item 2"));
                      JMenu submenu1 = new JMenu("submenu 1");
                      menu.add(submenu1);
                      submenu1.add(new JMenuItem("item 1.1"));
                      submenu1.add(new JMenuItem("item 1.2"));
                      JMenu submenu2 = new JMenu("submenu 2");
                      menu.add(submenu2);
                      submenu2.add(new JMenuItem("item 2.1"));
                      submenu2.add(new JMenuItem("item 2.2"));
                      JMenu submenu21 = new JMenu("submenu 2");
                      submenu2.add(submenu21);
                      submenu21.add(new JMenuItem("item 2.1"));
                      submenu21.add(new JMenuItem("item 2.2"));
                      menu.add(new JSeparator());
                      menu.add(new JMenuItem("item 3"));
                      menu.add(new JMenuItem("item 4"));
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.setSize(200, 200);
                      frame.add(menu);
                      frame.add(button);
                      button.addMouseListener(new Listener());
                      frame.setVisible(true);
                  }
              });
          }
      }
      --- End of source ---

      It is regression.

            mlapshin Mikhail Lapshin (Inactive)
            son Oleg Sukhodolsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: