See the sample code below. It simply creates a button and adds it to a window. But when *menu_item3* is selected, the ActionListener doesn't receive the event. This error only occurs on Java 7 for Mac. If I run this same code in Windows, it works fine. When I run this same code on Java 6 for Mac, it works fine. If I use a JFrame instead of JWindow, it works fine. I do not want to use a JFrame because I do not want to display the window title bar and border.
Any ideas?
public class SandBox {
public static JFrame frame = new JFrame();
public static JPopupMenu menu = new JPopupMenu();
public static JLabel button = new JLabel();
public static void main(String[] args) {
JFrame window = new JFrame();
JPanel panel = new JPanel();
JMenuItem menu_item1 = new JMenuItem("Item1");
JMenuItem menu_item2 = new JMenuItem("Item2");
JMenuItem menu_item3 = new JMenuItem("Item3");
menu.add(menu_item1);
menu.add(menu_item2);
menu.add(menu_item3);
menu.setEnabled(true);
button.setText("Button");
button.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, new Color(255,0,0)));
button.setSize(100, 24);
button.add(menu);
button.setVisible(true);
button.setEnabled(true);
panel.add(button);
panel.setVisible(true);
window.add(panel);
window.setVisible(true);
window.setLocation(100, 100);
window.setAlwaysOnTop(true);
window.setFocusable(true);
window.setFocusableWindowState(true);
window.pack();
frame.setVisible(false);
button.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
menu.show(button, 0, 0);
}
});
menu_item3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
}
});
}
}