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

主阶段关闭时JavaFX隐藏任务栏图标,java,javafx,awt,Java,Javafx,Awt,我随后创建了一个带有托盘图标的应用程序。当我关闭应用程序窗口时,任务栏上留下了一个图标。问题是当我关闭窗口时,如何隐藏任务栏上的图标?如果不可能,那么当我单击任务栏图标时,是否有方法返回窗口?非常感谢您提供跨平台的解决方案。您所链接的内容都是您想要的 重新打开JavaFX窗口的方法(包括两部分): : : 完全退出应用程序的方法: : 嗨,谢谢你的回答。但对于重新打开窗口,我试图说,关闭窗口后,按任务栏上的图标重新打开窗口。顺便说一句,我不确定您使用的是什么操作系统,但在macOS

我随后创建了一个带有托盘图标的应用程序。当我关闭应用程序窗口时,任务栏上留下了一个图标。问题是当我关闭窗口时,如何隐藏任务栏上的图标?如果不可能,那么当我单击任务栏图标时,是否有方法返回窗口?非常感谢您提供跨平台的解决方案。

您所链接的内容都是您想要的

  • 重新打开JavaFX窗口的方法(包括两部分):

    • :

    • :

  • 完全退出应用程序的方法:

    • :


  • 嗨,谢谢你的回答。但对于重新打开窗口,我试图说,关闭窗口后,按任务栏上的图标重新打开窗口。顺便说一句,我不确定您使用的是什么操作系统,但在macOS上,关闭最后一个窗口后,任务栏图标没有任何效果。上面在托盘图标中添加了一个操作侦听器,双击即可调用。如果这不能跨平台工作(它在Windows上工作),那么使用AWT可能不适合您的需要。我不知道还有其他托盘图标库。谢谢。我现在明白你的意思了。托盘图标确实有效,但我要求的是任务栏图标的解决方案。无法访问Mac,我无法使用一些代码。我不确定我能帮上忙。
    // instructs the javafx system not to exit implicitly when the last application window is shut.
    Platform.setImplicitExit(false);
    
    // 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));
    
    // 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);
    });