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