java - 为什么 JavaFX 应用程序任务管理器进程在关闭时不会结束

标签 java javafx

由于某种原因,我的应用程序中的某些进程即使在关闭应用程序窗口并退出后仍会继续。难道还有什么我没有考虑到的吗?我的应用程序定期生成系统托盘通知,但即使退出后这些通知也会继续。停止它的唯一方法是在任务管理器中找到 java.exe 进程。有什么我忽略的吗?

public class TrayNotification {

    public static void execute(String firstName, String incidentNumber, String requestId, TableView tabTable) throws AWTException, MalformedURLException {
        if (SystemTray.isSupported()) {
            TrayNotification trayNotification = new TrayNotification();
            trayNotification.displayTray(firstName, incidentNumber, requestId, tabTable);
        }
    }

    private void displayTray(String firstName, String incidentNumber, String requestId, TableView tabTable) throws AWTException, MalformedURLException {
        // Obtain a single instance of SystemTray
        SystemTray tray = SystemTray.getSystemTray();

        // Set TrayIcon values
        Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/images/tray-icon.png"));
        final TrayIcon trayIcon = new TrayIcon(image, "Remedy React Notification");
        trayIcon.setImageAutoSize(true);
        trayIcon.setToolTip(incidentNumber);

        // Add TrayIcon to SystemTray instance if possible
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            // System.out.println("Notification could not be added.");
        }

        trayIcon.addActionListener(e -> {
            Parent root = null;
            try {
                root = FXMLLoader.load(getClass().getResource("/fxml/scene.fxml"));
                root.requestLayout();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            System.out.println("Test");
        });

        // Display TrayIcon 
            trayIcon.displayMessage("Hey, " + firstName, "You are now tracking " + incidentNumber + " !", TrayIcon.MessageType.INFO);

    }

}

最佳答案

当用户单击“退出”按钮时,我正在使用 System.exit(0)

关于java - 为什么 JavaFX 应用程序任务管理器进程在关闭时不会结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45709126/

相关文章:

Java TransferHandler 与 Jbuttons 更新 Jbutton 文本

从 FXML 获取对象时 JavaFX 返回 null

Javafx tableview 上的复选框取消选中,禁用同一行但不同列上的按钮

java - 设置阿拉伯数字系统区域设置不显示阿拉伯数字

java - 什么时候应该在 Java EE 应用程序中使用 POJO(而不是 EJB)?

java - Hibernate查询超时异常-我无法将数据保存到数据库

java - 如何确保您的小程序不会在特定页面 URL 之外使用?

java - session.clear() 是必要的吗?

java - 使用按钮关闭 JavaFX 中的对话框

animation - Javafx titledpane 动画速度