/**
* 增加系统托盘
*/
private void addTray() {
// 创建系统托盘
// 判断系统是否支持系统托盘
if (SystemTray.isSupported()) {
// 创建系统托盘
SystemTray tray = SystemTray.getSystemTray();
// 创建弹出菜单
PopupMenu popup = new PopupMenu();
MenuItem exitItem = new MenuItem("exit");
exitItem.addActionListener(e -> System.exit(0));
popup.add(exitItem);
final Image image1 = Toolkit.getDefaultToolkit().getImage("app-daemon.png");
// 创建trayIcon
TrayIcon trayIcon = new TrayIcon(image1, "UhanApp", popup);
trayIcon.setImageAutoSize(true);
try {
tray.add(trayIcon);
} catch (AWTException e1) {
e1.printStackTrace();
}
}
}