gpt4 book ai didi

当主阶段关闭时JavaFX隐藏任务栏图标

转载 作者:行者123 更新时间:2023-12-02 09:13:39 25 4
gpt4 key购买 nike

我关注了this tutorial创建带有托盘图标的应用程序。当我关闭应用程序窗口时,任务栏上留下一个图标。问题是如何在关闭窗口时隐藏任务栏上的图标?如果不可能,那么当我单击任务栏图标时是否有办法恢复窗口?跨平台解决方案将不胜感激。

最佳答案

The gist您链接到的内容包含您正在寻找的一切。

  1. 重新打开JavaFX窗口的方法(涉及两部分):

    • Lines 39-40 :

      // instructs the javafx system not to exit implicitly when the last application window is shut.
      Platform.setImplicitExit(false);
    • Lines 106-112 :

      // if the user double-clicks on the tray icon, show the main app stage. 
      trayIcon.addActionListener(event -> Platform.runLater(this::showStage));

      // if the user selects the default menu item (which includes the app name),
      // show the main app stage.
      java.awt.MenuItem openItem = new java.awt.MenuItem("hello, world");
      openItem.addActionListener(event -> Platform.runLater(this::showStage));
  2. 完全退出应用程序的方法:

    • Lines 120-128 :

      // to really exit the application, the user must go to the system tray icon
      // and select the exit option, this will shutdown JavaFX and remove the
      // tray icon (removing the tray icon will also shut down AWT).
      java.awt.MenuItem exitItem = new java.awt.MenuItem("Exit");
      exitItem.addActionListener(event -> {
      notificationTimer.cancel();
      Platform.exit();
      tray.remove(trayIcon);
      });

关于当主阶段关闭时JavaFX隐藏任务栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59182839/

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