gpt4 book ai didi

java - 如何从系统托盘打开应用程序?

转载 作者:行者123 更新时间:2023-12-02 05:55:31 25 4
gpt4 key购买 nike

如何通过关闭按钮发送系统托盘中的java应用程序并通过单击系统托盘图标恢复?

我尝试过隐藏,但现在如何通过单击系统托盘来取回它?

 getFrmTaskList().setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

任何人都可以给我适当的建议吗?已经通过在搜索框中搜索尝试了所有其他方式

最佳答案

    This is example code you can create appropriate listener and make it working
//Check the SystemTray is supported
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon =
new TrayIcon(createImage("images/bulb.gif", "tray icon"));
final SystemTray tray = SystemTray.getSystemTray();

// Create a pop-up menu components
MenuItem aboutItem = new MenuItem("About");
CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
Menu displayMenu = new Menu("Display");
MenuItem errorItem = new MenuItem("Error");
MenuItem warningItem = new MenuItem("Warning");
MenuItem infoItem = new MenuItem("Info");
MenuItem noneItem = new MenuItem("None");
MenuItem exitItem = new MenuItem("Exit");

//Add components to pop-up menu
popup.add(aboutItem);
popup.addSeparator();
popup.add(cb1);
popup.add(cb2);
popup.addSeparator();
popup.add(displayMenu);
displayMenu.add(errorItem);
displayMenu.add(warningItem);
displayMenu.add(infoItem);
displayMenu.add(noneItem);
popup.add(exitItem);

trayIcon.setPopupMenu(popup);

try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}

关于java - 如何从系统托盘打开应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23128956/

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