JDK-4127402 : Mouse clicks on menu are propagated to underlying component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.5,1.1.6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6,windows_nt
  • CPU: x86,sparc
  • Submitted: 1998-04-09
  • Updated: 1998-07-07
  • Resolved: 1998-07-07
Related Reports
Duplicate :  
Duplicate :  
Description

Name: rk38400			Date: 04/09/98


System is JDK 1.1.5, Swing 1.0, Solaris 2.5.  The following program doesn't
behave as expected.
 
Clicking on the button generates the message 'button'.  Clicking in the
panel generates the message 'mouse click'.  Selecting the menu item 'Item'
*sometimes* generates the messages 'menu item' *and* 'mouse click'.  It
seems to happen very often when the menu item is first selected.  After
a number of selections it then reverts to the behaviour I'd expect,
only printing 'menu item'.  Leaving the program quiescent for a while
causes the wrong behaviour to reappear.  If the window is resized so
that a heavyweight menu is used the behaviour is as expected.
 
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
 
public class menubug extends JFrame {
 
    public menubug() {
        JPanel panel = new JPanel(new BorderLayout()) ;
        getContentPane().add(panel) ;
 
        JMenuBar mb = new JMenuBar() ;
        JMenu file = new JMenu("File") ;
        mb.add(file) ;
        JMenuItem item = new JMenuItem("Item") ;
        file.add(item) ;
        item.addActionListener(new ItemListener()) ;
        JMenuItem exit = new JMenuItem("Exit") ;
        file.add(exit) ;
        exit.addActionListener(new ExitListener()) ;
 
        JPanel panel2 = new JPanel() ;
        panel2.addMouseListener(new MyMouseAdapter()) ;
 
        JButton button = new JButton("Button") ;
        button.addActionListener(new MyButtonListener()) ;
 
        panel2.add(button) ;
 
        panel.add(mb, "North") ;
        panel.add(panel2, "Center") ;
 
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e)
            {System.exit(0);}}) ;
 
        pack() ;
        setBounds(200, 200, 640, 400) ;
        setVisible(true) ;
    }
 
    public class ItemListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.out.println("menu item") ;
        }
    }
 
    public class MyButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.out.println("button") ;
        }
    }
 
    public class ExitListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.exit(0) ;
        }
    }
 
    public class MyMouseAdapter extends MouseAdapter {
        public void mouseClicked(MouseEvent e) {
            System.out.println("mouse click") ;
        }
    }
 
    public static void main(String s[]) {
        menubug m = new menubug() ;
    }
 
}
(Review ID: 25984)
======================================================================

Comments
EVALUATION I think this is already reported, but since I can't find the report, I'll look at this seperately. This is weird, it is almost like it might be a bug in the lightweight dispatcher rather than the menu code. It does still happen with the rewrite... georges.saab@Eng 1998-06-01 Verified that it is a bug in the lightweight dispatcher. Reported as bug 4155217. georges.saab@Eng 1998-07-07
01-06-1998