坐落在啓動方法下列財產
Platform.setImplicitExit(false);
然後設置上緊密事件
secondaryStage.setOnCloseRequest(event -> {
// Your code here
});
爲了使ystem托盤嘗試以下代碼:
原始文檔鏈接:https://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html
//Check the SystemTray is supported
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
URL url = System.class.getResource("/images/new.png");
Image image = Toolkit.getDefaultToolkit().getImage(url);
final TrayIcon trayIcon = new TrayIcon(image);
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.");
}
實施例的系統托盤圖像:
要從AWT事件處理程序調用的JavaFX的方法可能會follw以下方式:
yourAwtObject.addActionListener(e -> {
Platform.runLater(() -> primaryStage.show());
});
有n o在javafx中的內置功能。這可以通過一些工具(在Windows中)將應用程序圖標化爲系統托盤來完成。只有一個是在https://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html中。如果你說德語,有一個很好的指南可以讓它發生在javafx上:http:// blog。 essential-bytes.de/wie-man-javafx-applikationen-in-das-system-tray-verbannt/或英文jewelsea:https://gist.github.com/jewelsea/e231e89e8d36ef4e5d8a – NwDev
謝謝!當初級舞臺關閉時,我該如何關閉第二個窗口? –