gpt4 book ai didi

java - JMenu setDelay() 弹出延迟

转载 作者:行者123 更新时间:2023-12-01 15:55:05 24 4
gpt4 key购买 nike

在我的应用程序中,我有一个 JPopupMenu,它显示一组子菜单:

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();
}

此应用程序通常在 Windows 上运行。

我首先将鼠标悬停在第一个 XXX 子菜单上。有时,我不小心将鼠标移到 YYY 上,导致第一个子菜单立即消失。

从阅读 Javadoc 来看,调用 JMenu.setDelay(2000) 似乎应该建议 JMenu 的弹出菜单在弹出之前等待 2 秒。然而,它似乎只是延迟了下一个菜单2秒才弹出。

有办法延迟弹出吗?

最佳答案

更新

这里有一些有趣的事情;来自Bug #6563939 Delay should be respected before hiding a JMenu, open since 2007

Javadoc might be misleading in this point. It says "before submenus are popped up or down". "Popping down" could be understood as "hiding", but it rather has the meaning of "submenu is rendered below his parent menu".

<小时/>

它还有seems to suggest that this depends on the L&F you're using ,所以它看起来更像是你只能请求或暗示的东西:

Each look and feel (L&F) may determine it's own policy for observing the delay property. In most cases, the delay is not observed for top level menus or while dragging. This method is a property of the look and feel code and is used to manage the idiosyncracies of the various UI implementations.

关于java - JMenu setDelay() 弹出延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com