系统托盘弹出菜单项与图像(IconItem的图标) [英] System Tray Pop up menu item with Image(Icon to the MenuItem)
问题描述
我阅读了系统托盘教程和这个类似的Stack Overflow问题但找不到一个很好的答案。我想在J2SE应用程序中添加一个图像到菜单项。在教程中,使用了 MenuItem
,但我找不到如何在SystemTray弹出窗口中向菜单项添加图标。如果使用 JMenuItem
,可以轻松地将图标放在 MenuItems
中,但是 MenuItem
。如何将图像添加到系统托盘popmenu?
I read the system tray tutorial and this similar Stack Overflow question but can't find a good answer. I want to add an image to menu item in J2SE application. In the tutorial, MenuItem
is used, but I couldn't find how to add icons to menu items in SystemTray pop up. If JMenuItem
is used, icons can easily be placed in MenuItems
, but there is MenuItem
. How can I add an image to my system tray popmenu?
已更新此处,我想将图像添加到 MenuItem
在弹出菜单中(而不是SystemTray。)
UpdatedHere, I want to add an image to MenuItem
in the popup menu(not to the SystemTray.)
推荐答案
你可以使用 JPopupMenu
使用 TrayIcon
(在这里阅读)。
trayIcon.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
jpopup.setLocation(e.getX(), e.getY());
jpopup.setInvoker(jpopup);
jpopup.setVisible(true);
}
}
});
这篇关于系统托盘弹出菜单项与图像(IconItem的图标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!