我有一个2阶段的应用程序,我不希望用户关闭第二阶段,只是图标化它.
目前我正在使用oncloseRequest处理程序来最小化窗口 –
secondaryStage.setOnCloseRequest(event -> {
secondaryStage.setIconified(true);
event.consume();
});
我想在用户关闭窗口时在系统托盘中显示一个图标.并且用户应该能够从托盘重新打开窗口.
另外,如何确保初级阶段何时关闭,第二阶段也关闭?
最佳答案 在start方法中设置以下属性
Platform.setImplicitExit(false);
然后设置on close事件
secondaryStage.setOnCloseRequest(event -> {
// Your code here
});
要制作系统托盘,请尝试以下代码:
//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 t