效果图
悬停:
SystemTray tray = SystemTray.getSystemTray();
PopupMenu pm = new PopupMenu();
//设置图标
BufferedImage image = ImageIO.read(Main.class
.getResourceAsStream("trayicon.png"));
//设置右键菜单
MenuItem mi = new MenuItem("exit");
//右键菜单监听
mi.addActionListener(e -> {
//点击右键菜单退出程序
System.exit(0);
});
pm.add(mi);
//设置悬停提示信息
TrayIcon trayIcon = new TrayIcon(image, "screenShot", pm);
tray.add(trayIcon);