The following program shows that mouse events are still falling through
from Swing menus to the underlying components:
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* This demo shows events from a JMenu / JMenuItem falling through to
* a JPanel.
*
* @author Todd C. Parnell, ###@###.###
*/
public class Test extends JFrame {
public static void main(String[] args) {
Test t = new Test();
}
public Test() {
super("JMenu / JPanel event test");
JMenuBar menubar = new JMenuBar();
this.setJMenuBar(menubar);
JMenu menu = new JMenu("File");
menubar.add(menu);
JMenuItem menuitem = new JMenuItem("test");
menuitem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("got menu click");
}
});
menu.add(menuitem);
JPanel jp = new JPanel();
jp.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println("jpanel got click");
}
});
this.getContentPane().add(jp);
this.setSize(100, 100);
this.show();
}
}