如何制作Java TrayIcon MenuItem快捷方式?
我很难在 TrayIcon 弹出菜单上创建快捷方式。
以下是我的代码。
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(createImage("images/bulb.gif", "tray icon"));
final SystemTray tray = SystemTray.getSystemTray();
//MenuItem aboutItem = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A));
MenuItem aboutItem = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A, false));
Menu settingMenu = new Menu("Settings");
MenuItem exitItem = new MenuItem("Exit");
popup.add(aboutItem);
popup.addSeparator();
popup.add(settingMenu);
popup.addSeparator();
popup.add(exitItem);
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"This dialog box is run from the About menu item");
}
});
我坚持了这一点。 为什么当我按“a”键时我的程序不起作用? 我怎样才能正确地做到这一点? 我想在弹出菜单上表达一个快捷键,例如在底部“a”字符下划线。
I have difficulty to make a shortcut on TrayIcon popup menu.
Followings are my codes.
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(createImage("images/bulb.gif", "tray icon"));
final SystemTray tray = SystemTray.getSystemTray();
//MenuItem aboutItem = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A));
MenuItem aboutItem = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A, false));
Menu settingMenu = new Menu("Settings");
MenuItem exitItem = new MenuItem("Exit");
popup.add(aboutItem);
popup.addSeparator();
popup.add(settingMenu);
popup.addSeparator();
popup.add(exitItem);
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"This dialog box is run from the About menu item");
}
});
I stuck this point.
Why my program doesn't work when I press 'a' key?
How can I make it properly?
and I want to express a is shorcut key on popup menu such as underline bottom 'a' character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是带有 keyMnemonic 和 keyAccelerator 的正确且更正的代码,该代码将在 A
希望这有帮助下放置行。
Here is the proper and corrected code with keyMnemonic and keyAccelerator that will placed line under A
Hope this helpfull..
例如 http://www.javaswing.org/java-swing-popup-menu .aspx
for example http://www.javaswing.org/java-swing-popup-menu.aspx