In my application, I have a JPopupMenu that displays a set of sub-menus:
private static JMenu createMenu(String title) {
JMenu menu = new JMenu(title);
menu.setDelay(2000);
menu.add(new JMenuItem("123"));
menu.add(new JMenuItem("234"));
menu.add(new JMenuItem("345"));
return menu;
}
public static void main(String[] args) {
JFrame frame = new JFrame("Hello");
final JButton button = new JButton("Test");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JPopupMenu jpm = new JPopupMenu();
jpm.add(createMenu("XXX"));
jpm.add(createMenu("YYY"));
jpm.add(createMenu("ZZZ"));
jpm.show(button, 0, 0);
}
});
frame.add(button);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
}
This application usually runs on Windows.
I first mouse-over the first XXX sub-menu. Sometimes, I accidentally move my mouse over YYY, which then causes the first sub-menu to disappear immediately.
From reading the Javadoc, it would seem that calling JMenu.setDelay(2000) should suggest that the JMenu's popup menu wait 2 seconds before popping down. However, it only seems to delay the next menu 2 seconds before popping up.
Is there a way to delay the pop down?